11-day11-if-for-while
11-day11-if-for-while
-
export age //声明全局变量
-
$ ${} $[]
[root@bogon ~]# echo $age 100 [root@bogon ~]# echo ${age} 100 [root@bogon ~]# echo $[age] //$[]是可以计算 100 [root@bogon ~]# echo $[10%3] 1 [root@bogon ~]# echo $[10/3] 3
-
(( ))
[root@bogon ~]# age=100 [root@bogon ~]# ((age >10)) [root@bogon ~]# echo $? 0
-
关系运算符 与(())连用
< > <= >= == != && || //*****// c+ 与 ((c+)) [root@bogon ~]# c=2 [root@bogon ~]# c+=2 [root@bogon ~]# echo $c 22 [root@bogon ~]# b=3 [root@bogon ~]# ((b+=3)) [root@bogon ~]# echo $b 6
-
test命令 [] 可以达到同样的效果
[ $x -gt 1 ] [ $user = 'cx2c' -a $password='cx2c' ] //a 是and [ $user = 'cx2c' -o $password='cx2c' ] //o是or [root@localhost cx2c]# cat chech_file.sh #!/bin/bash read -p "please input file " file if [ -b $file ];then echo "$file is a block" elif [ -f $file ];then echo "$file is a file" elif [ -d $file ];then echo "$file dict" else echo "unknow" fi
-
shell里所有的计算器
$[] (()) $(()) expr bc bc -l echo 'scale=2;1/3'|bc -l | cut -d'.' -f2 [root@bogon ~]# expr 1+2 1+2 [root@bogon ~]# expr 1 + 2 3
-
测试命令 test [] [[]] (())
[root@bogon ~]# test -n '' [root@bogon ~]# echo $? 1 [root@bogon ~]# test -n 'ads' [root@bogon ~]# echo $? 0 [root@bogon ~]# [ -n 'ads' ] [root@bogon ~]# echo $? 0
-
判断
-eq: 等 -ne:不等 -gt:大于 -ge:大于等于 -lt:小于 -le:小于等于 -b:块设备 -d:文件夹 -e:文件存在 -f:文件存在
-
VISUAL BLOCK 编辑模式
ctrl+v 上下选择光标选择行 I进入insert 位置首行 写入# 两下esc
-
shell read
read -p 'Please Input your username' username
-
if while 判断文件类型
#!/bin/bash read -p "please input file " file while : do if [ -z $file ];then read -p "please input file " file continue else break fi done if [ -b $file ];then echo "$file is a block" elif [ -f $file ];then echo "$file is a file" elif [ -d $file ];then echo "$file dict" else echo "unknow" fi
-
while 循环
while ((count <10)) do ... done
-
if 循环
if [ -z $file];then ... elif[ !-z $file];then ... else ... fi
-
for循环
WHILE : DO DONE FOR (( )) DO DONE 双小括号 不用$ while 标志位
-
输入账号密码授权执行命令-tag
-
输入账号密码授权执行命令
-
if [] 判断
-
输入账号密码授权执行命令
-
打印乘法表
-
判断路径文件类型
-
创建30用户并且设置密码