Reputation: 29
So I am trying to output a file with the name of like: lastlogin-"yyyymmdd" where it contains the current date.
I figured out the date should be : date +"%Y%m%d"
and I tried to do a variable
now = date +"lastlogin-%Y%m%d.txt"
filename = ${now}
xxxxx > ${filename}
but nothing seems to work
Please help
Upvotes: 2
Views: 13580
Reputation: 27496
You should use $()
for command execution and storage of result:
now=$(date +"lastlogin-%Y%m%d.txt")
Upvotes: 1
Reputation: 42107
Use command substitution:
lastlogin-"$(date '+%Y%m%d')".txt
To save in a variable:
filename="lastlogin-"$(date '+%Y%m%d')".txt"
and then do:
echo 'foobar' >"$filename"
Upvotes: 4