Reputation: 41
Using bash, I need to add to the end of a file, on the same line a string followed by the date. Example "Rebooted on Mon Aug 13 10:38:56 PDT 2012"
echo -n "Reboot done on " ; date
This gives me what I want on one line, but I can't append to the text file.
echo -n "Reboot done on " ; date > test.txt
This does not seem to work for me. It only gives me the date.
Thanks in advance.
Upvotes: 3
Views: 11780
Reputation: 399
This is because your output Reboot done on with echo and then you execute date
and put its output into the file. Try this instead:
echo "Reboot done on $(date)" > test.txt
Upvotes: 6