欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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
相关标签: Unix