您的位置:首页 > 运维架构 > Shell

shell 练习

2012-11-29 13:29 155 查看
$ {} 注意:

[root@localhost Exercise]# num=2
[root@localhost Exercise]# echo $num
2
[root@localhost Exercise]# echo this is $numnd
this is
[root@localhost Exercise]# echo this is {$num}nd
this is {2}nd
[root@localhost Exercise]# echo this is ${num}nd
this is 2nd
[root@localhost Exercise]#


shell的赋值 默认是字符串赋值:

[root@localhost Exercise]# var=1
[root@localhost Exercise]# var=$var+1
[root@localhost Exercise]# echo $var
1+1
[root@localhost Exercise]#

let:

[root@localhost Exercise]# A=1
[root@localhost Exercise]# let A++
[root@localhost Exercise]# echo $A
2
[root@localhost Exercise]# let "A++"
[root@localhost Exercise]# echo $A
3
[root@localhost Exercise]#

$ {}:

[root@localhost Exercise]# echo $A
3
[root@localhost Exercise]# A=$[$A+1]
[root@localhost Exercise]# echo $A
4
[root@localhost Exercise]#
()两个括号:注意!!!

[root@localhost Exercise]# A=1
[root@localhost Exercise]# echo $A
1
[root@localhost Exercise]# A=$(($A+1))
[root@localhost Exercise]# echo $A
2
[root@localhost Exercise]# A=$($A+1)
bash: 2+1: command not found
[root@localhost Exercise]#


[root@localhost Exercise]# echo $(5)
bash: 5: command not found

[root@localhost Exercise]# echo $((5))
5
[root@localhost Exercise]#
[ ] 一个即可:

[root@localhost Exercise]# echo $[5]
5
[root@localhost Exercise]# echo $[[5]]
bash: [5]: syntax error: operand expected (error token is "[5]")
[root@localhost Exercise]#


[ ] 这两个符号的前后都要空格,等号两边不能空格:

#!/bin/bash
#myshell
if [ $SHELL="bin/bash" ];then
echo "your login is $SHELL"
fi
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: