1,$$: Displays the current process ID number
[Email protected]:~/linux/shell/how_to_use_var$CatShow_pid.SH #!/bin/BashEcho $$Sleep the[email protected]:~/linux/shell/how_to_use_var$ bash show_pid.SH&[1]9401[email protected]:~/linux/shell/how_to_use_var$9401[email protected]:~/linux/shell/how_to_use_var$PS-ef |grepSHOW_PIDGHOSTWU9401 2792 0 .: -pts/ - xx:xx:xxBash Show_pid.SHGHOSTWU9404 2792 0 .: -pts/ - xx:xx:xx grep--color=auto Show_pid
PS grep grep grep GHOSTWU 9401 2792 0 : pts/ : xx : Show_pid bash. SH
[email protected]:~/linux/shell/how_to_use_var$ kill 9401 [email protected]: ~/linux/shell/how_to_use_var$ ps -ef | grep SHOW_PIDGHOSTWU 9478 2792 0 06 : 08 pts/18 00 : 00 : 00 grep --color=auto show_pid[ 1 ]+ Terminated bash show_pid.sh
2, (()) Common operators for integers
> Assigns the result of two integers to a variable, preceded by $
[Email protected]:~/linux/shell/how_to_use_var$ a= ((ten+)) Bash:syntax error near unexpected Token ' ('[email protected]:~/linux/shell/how_to_use_var$ a=$ (++)] [email Protected]:echo $a
3, arithmetic
[Email protected]:~/linux/shell/how_to_use_var$ Bash Calc.SH Ten 2a+b= Aa-b= Aa*b= Aa/b= Aa**b= -a%b=0[email protected]:~/linux/shell/how_to_use_var$CatCalc.SH #!/bin/Basha=$1b=$2Echo "a+b=$ (($a + $b))"Echo "a-b=$ (($a + $b))"Echo "a*b=$ (($a + $b))"Echo "a/b=$ (($a + $b))"Echo "a**b=$ (($a * * $b))"Echo "a%b=$ (($a% $b))"
4,let for integer operations, similar (())
[Email protected]:~/linux/shell/how_to_use_var$ i=[email protected]:~/linux/shell/how_to_use_ var$ let i=i+[email protected]:echo $i
Does not use let, the value of the variable is not evaluated
[Email protected]:~/linux/shell/how_to_use_var$ i=2[email protected]:~/linux/shell/how_to_use_ var$ i=i+8[email protected]:echo $ii+8
5,bash built-in command read, reading the value of the variable via the parameter-P prompt message
" pls input 2 number: " 2 number:[email protected]:echo $a $b10 -
10,test-f to determine if a common file exists
ls ghostwu.txt output_error.txt std_out1.txt std_out.txt[email protected]:echo1 Echo01[email protected]:echo1echo 0 0
Test-z test if the string length is 0
" Hello " Echo 1 Echo 0 0 [email protected]: "" Echo 1 Echo 0 1
The brackets [] are the same as test.
Echo 1 Echo 0 1 [email protected]: Echo 1 Echo 0 0
11, determine whether a variable value or string is an integer?
When using expr, a variable or string must be an integer rule, adding a variable or string to a known integer (not 0) to see if the value returned by the command is 0. If 0, the variable or string that does the addition is considered an integer, otherwise it is not an integer.
[Email protected]:~/linux/shell/flow_control$ i=Ten[email protected]:~/linux/shell/flow_control$Expr$i +1>/dev/NULL[email protected]:~/linux/shell/flow_control$Echo$?0[email protected]:~/linux/shell/flow_control$ i='a'[email protected]:~/linux/shell/flow_control$Expr$i +1>/dev/NULL 2>&1[email protected]:~/linux/shell/flow_control$Echo$?2
Linux shell scripts-variable speed entry and Advanced (2)