linux中$与()的一点使用疑惑解释
a=$(cat 1.sh)
等价于
a=`cat 1.sh`
而
a=(cat 1.sh) 相当于定义一个a数组,内容为cat 1.sh
a=(`cat 1.sh`)相当于把1.sh里面的内容当成a的数组,a仍旧是一个数组
a=$(`cat 1.sh`)此命令会报错,不能执行
[root@zejin240 chenzejin]# cat 1.sh
hello world 2016
better
[root@zejin240 chenzejin]# a=(cat 1.sh)
[root@zejin240 chenzejin]# b=(`cat 1.sh`)
[root@zejin240 chenzejin]# c=$(cat 1.sh)
[root@zejin240 chenzejin]# d=`cat 1.sh`
[root@zejin240 chenzejin]# echo ${a[@]}
cat 1.sh
[root@zejin240 chenzejin]# echo ${b[@]}
hello world 2016 better
[root@zejin240 chenzejin]# echo ${c[@]}
hello world 2016 better
[root@zejin240 chenzejin]# echo ${d[@]}
hello world 2016 better
[root@zejin240 chenzejin]# echo $a
cat
[root@zejin240 chenzejin]# echo $b
hello
[root@zejin240 chenzejin]# echo $c
hello world 2016 better
[root@zejin240 chenzejin]# echo $d
hello world 2016 better
[root@zejin240 chenzejin]# e=$(`cat 1.sh`)
-bash: hello: command not found