#!/bin/bash#你值得收藏的四则表达式运算. val1=1Val2=1val3=1val4=1val5=1val6=1val7=1 Letval1++ ((val2++)) val3=$ (($val 3+1)) val4= ' expr$val 4+1' Val5= ' bc<<<$val 5+1' Val6= 'Echo "$val 6+1"|BC ' val7=$[$val 7+1]Echo ' val1= ' $val 1Echo ' val2= ' $val 2Echo ' val3= ' $val 3Echo ' val4= ' $val 4Echo ' val5= ' $val 5Echo ' val6= ' $val 6Echo ' val7= ' $val 7
You should be aware of conditional control statements.
#!/bin/bash#Val=1ifTest$val -eq 1; ThenEcho "Hello word!"fi#!/bin/bash#Val=1if[$val -eq 1]; ThenEcho "Hello word!"fi#!/bin/bash#Val=1[$val -eq 1] && {Echo "Hello word!"}#[]//does not support regular expressions, it is a system command. #[[]]//supports regular expressions, but not system commands. #!/bin/bashVal=1[[$val -eq 1]] && {Echo "Hello word!"}
#!/bin/bash#输入一个用户判断该用户是否存在. #read-P "Please input your User:" User#a = ' cut-d ': "-f1/etc/passwd| grep "$USER" ' while true Do if["$USER"=="$a"]; Then Echo "Yes!this user is exit!!!" Break Else Echo "This user no Exit!!!" Read-P"Please input it again:"USER a= ' cut- D ":" - F1/etc/passwd| Grep"$USER"`fi Done
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Shell Script [op-expression, conditional-control statement]