November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

dynamic date value in shell scripts

dynamic date value in shell scripts
using a variable – easier to read in scripts:
NOW=$(date +”%Y%m%d%H%M%S”)
echo “bar” > “$NOW”foobar.txt

one-line, equivalent to above:
echo “bar” > $(date +”%Y%m%d%H%M%S”)foobar.txt

alternate single-line format:
echo “bar” >> $(date “+myfile%Y%m%d.txt”)

man strftime to see formatting values

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>