What does the command $()
do in UNIX? Could someone explain what is the significance of $
in the below examples;
$(echo var=10)
and
eval $(echo var=10)
What does the command $()
do in UNIX? Could someone explain what is the significance of $
in the below examples;
$(echo var=10)
and
eval $(echo var=10)
This isn't a command itself, rather this is an example of command substitution. It takes the value of what is in parentheses and uses it in context.
For example, I will frequently make a backup of a file before editing it. I'll use command substitution to add the date to the end of the filename in ISO 8601 format (for sorting.) Of course, I could just type the date, but this is great for scripts where the date may be different each time it runs.
$ cp -p /path/to/file /path/to/file.$(date +%F)
$ ls /path/to/file.*
/path/to/file.2013-09-10 /path/to/file
$(echo something)
was always written \
echo something`` before, and you easily overlook those backticks, especially on a cheap printer.
– ott--
Sep 10 '13 at 20:40
man bash
for “$(”. (Depending on your man pager, you may need to write the search expression as “$\(”.) – manatwork Sep 10 '13 at 17:33$()
in the title -- which I don't see in the "Related" sidebar, and that is what people will look for if they don't know it is about command substitution. So thank you for asking that way! – goldilocks Sep 10 '13 at 17:41