简体   繁体   中英

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.

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

尝试这个

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

这是另一种方式:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM