Bash Difference between ${} and $()
程序员文章站
2022-07-11 08:12:12
...
Difference between ${} and $()
1, $(command) is “command substitution”. it runs the command, captures its output, and inserts that into the command line that contains the $(…);
eg:
$ ls -ld $(date +%B).txt
-rwxr-xr-x 1 Noob Noob 867 Jul 2 11:09 July.txt
$ echo $(date)
Thu Jul 2 16:33:11 SGT 2015
2, ${parameter} is “parameter substitution”.
The ${…} form,lets you get the value of a variable.
eg:
animal=cat
echo $animals
$ No such variable as “animals”.
echo ${animal}s
$ cats
echo $animal_food
$ No such variable as “animal_food”.
echo ${animal}_food
$ cat_food