I have created a linux bash script directory structure which is all working fine except from the date is not showing in the logfile which is created!
Here is the code for the logfile
touch $1/logfile.log
CURRENTDATE=`date +"%Y-%m-%d %T"`
printf "Created by: $USER\nDate/Time Created: $CURRENTDATE" > $1/logfile.log
The message from the command line I receive is: CURRENTDATE: Command Not Found, then when opening the logfile.log created the correct USER appears but there is no date.
Any Advise? Thanks
You should use "echo" not printf if you are using linux.
talha@DESKTOP-BCDU8TA:~$ touch logfile.log
talha@DESKTOP-BCDU8TA:~$ echo -e "Created by: $USER\nDate/Time Created:$CURRENTDATE" > logfile.log
talha@DESKTOP-BCDU8TA:~$ cat *log
Created by: talha
Date/Time Created: 2021-10-30 20:57:48
So as you can see on the code sample it worked.
尝试使用 echo 命令:
echo -e "Created by: $USER\nDate/Time Created: $CURRENTDATE" > $1/logfile.log
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.