Assigning values to variables
Defining an integer class using Declare-i
[[email protected] scripts]# Aa=5+6[[email protected] scripts]# echo $aa 5+6[[email protected] scripts]# declare-i Aa[[ema Il protected] scripts]# aa=5+6[[email protected] scripts]# echo $AA 11
With let, you don't need to define an integral type
[[email protected] scripts]# let Bb=1+8[[email protected] scripts]# echo $bb 9[[email protected] scripts]# cc=$ ((5+8)) [[Em AIL protected] scripts]# echo $CC 13
echo $? return value
Test compare two worth of size
-eq-lt-le-gt-ge
Aa=3 bb=4
Test $aa-eq $BB
echo $?
Test $aa-lt $BB
echo $?
Judgment 1 | | Judgment 2
[-F/ETC/PASSWD] Determine if the file exists
echo $?
0
[-R/ETC/PASSWD]
echo $?
0
[Email protected] scripts]# aa=3 bb=4[[email protected] scripts]# [$aa-lt $BB] && echo okok[[email protected] scripts]# [$aa-gt $bb] && echo OK [[email protected] scripts]# [$aa-gt $BB] | | echo OK OK
Judging the Code
[[email protected] scripts]# vim if.sh#!/bin/bashgrep-q ^$1/etc/passwdif ["$?"-eq 0]; Then echo "$ is exist" else echo "exist" fi
If...then
[Email protected] scripts]# vim age.sh#!/bin/bashread-p "Please input your Age:" Ageif ["$age"-le 0] | | ["$age"-ge 100]; then echo "Please input correct age" Read Ageelif ["$age"-GT 0] && ["$age"-lt 20]; Then echo "Junior" Elif ["$age"-ge] && ["$age"-lt 50]; Then echo "You is adult" else echo "You is old" fi
While loop
[Email protected] scripts]# vim sum.sh#!/bin/bashsum=0while [$sum-lt]do let Sum+=1 echo $sumdone
#!/bin/bashread-p "Please input your name:" Namewhile ["$name"! = Tom] do echo "Please input correct name" Read namedone~
[[email protected] scripts]# vim case.sh#!/bin/bashxx=0until [ "$xx" -gt 24 ]do case "$xx" in              [0-9]|1[01]) echo "Good morning" ;;                 12) echo "It ' S lunch time" ;;                 1[3-7]) echo "Good afternoon" ;; *) echo "Good evening" esac let xx+=1done
Learn shell scripts