Which of the following commands puts the output of the command date into the shell variable mydate?
Which of the following commands puts the output of the command date into the shell variable mydate?
To put the output of the command date into the shell variable mydate, you should use command substitution. The correct syntax for command substitution in a shell script is to enclose the command in $(..). Therefore, mydate=$(date) will execute the date command and assign its output to the mydate variable.
root@CT101:~# echo $mydate Tue Jun 25 11:05:20 UTC 2024 root@CT101:~#
root@CT101:~# mydate="$(date)" root@CT101:~# echo $mydate Tue Jun 25 11:05:20 UTC 2024 root@CT101:~#