dee doo
dee doo

Reputation: 41

Append on the same line bash

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

Answers (3)

drjd
drjd

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

Aoife
Aoife

Reputation: 1736

Here's another way:

(echo -n "Reboot done on "; date) > test.txt

Upvotes: 1

Debaditya
Debaditya

Reputation: 2497

Try this

echo -n "Reboot done on `date`" > test.txt

Upvotes: 3

Related Questions