When writing a shell script, you may want to use the output result of the `command in the shell script. `` You can use command substitution to ** get the result of a command as a string **.
If you write the command you want to execute in parentheses in the format
$ (), it will be replaced with the standard output when the shell script is executed.
$ date '+%Y-%m-%d' 2020-05-04
#!/bin/bash filename=$(date '+%Y-%m-%d') touch "$filename"
Doing this will create a file with the current date in YYYY-MM-DD format.
-rw-rw-r-- 1 vagrant vagrant 0 May 4 10:54 2020-05-04
New Linux textbook