shell 练习
2012-11-29 13:29
155 查看
$ {} 注意:
shell的赋值 默认是字符串赋值:
let:
$ {}:
[ ] 这两个符号的前后都要空格,等号两边不能空格:
[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
相关文章推荐
- shell 练习002 (20160228)
- shell练习(2)--awk统计ip访问量(一条命令)
- shell脚本 回顾 小练习
- shell命令小练习,显示日期时间及一句话
- shell脚本练习(12.11)
- shell下的基础程序题练习
- 练习--hive查询实例和Shell去重
- shell语法练习之实现简单读取文件
- Shell练习获取彩票开奖结果
- Shell练习 行列转换
- shell脚本小练习
- shell脚本练习 :备份文件(2)修订
- 【脚本练习】shell脚本
- 12-Shell脚本_练习
- shell练习
- 练习shell脚本
- 01.6 shell的函数练习
- shell脚本的简单练习
- linux语句和shell的反复练习
- shell命令小练习,显示日期时间及一句话