shell 中的() 与{}

1470阅读 0评论2015-10-08 怪怪虎
分类:LINUX

1) ()相当于子shell 中执行某些command; (command1; command2)这些command不会真正的改变现在shell的。
(cd -; ls;) 显示上一个目录的文件,但是本身还是停留在当前目录。
     hi=(cd -; ls;)  这种赋值方式是不对的
hi=$(cd -; ls;)
2) {} 相当于在当前shell中执行花括号里的命令。
       {cmd1; cmd2;}
2-) ${ } 相当于变量替换。也有相当多的规则。

3) hi=$() 相当于把()里面的command的结果赋值给hi . 如果没有结果的话,就是空 如 cd /
     hi=$(cd /)   ==> cd /没有返回值。

4) (( )) 可以用来做四则运算
  num=6
     num=$((num+1))
     (()) 可以用来做比较
               == > >= < <= !=
            不适用于-gt -eq 之类的。
               [root@computer3 /]# ((num -gt hi))
                    -bash: ((: num -gt hi: syntax error in expression (error token is "hi")
    (( ))里面的变量可以暂时不用加$

=====
[root@computer3 /]# 6
-bash: 6: command not found
[root@computer3 /]# =6
-bash: =6: command not found
[root@computer3 /]# a=6
[root@computer3 /]# echo $a
6
=====


上一篇:go 变量
下一篇:shell 中 引用