Variable definition and use
$var =value------don't add spaces around the equals sign
$echo $var--$var to reference a variable
$age = 20--Variable assignment
$echo "She is $age"--reference variable in string, ${age}, can distinguish variable boundary
Environment variables
$echo ${path}--like the PATH variable under win
$PATH = "$PATH:/home/user/jdk1.6.1/bin"
$export PATH-A script execution that can specify environment variables, modify or delete environment variables, only valid for this script execution, not permanently valid
Other uses of variables
$var =123456
$echo ${#var}--Get the length of the variable
$echo $SHELL--Displays the current SHELL version information
A simple if operation
if [$UID-ne 0] Then echo "not Root." Else echo "Root User." fi
Note: If the Terminator is fi, this notation is more common in Linux. -ne,-eq,-gt,-lt is used to compare integers. ==,!= is used to compare characters. There is a space between if and [. $UID is the ID of the current logged-on user.
A simple operation
Num1=1;
num2=2;
Let result=num1+num2;
Echo $result
Note: Using let for simple operations, floating-point numbers are not supported.
Mathematical Operations advanced Tools BC
echo "4*0.11" | BC-Output:. 44. | For the pipe symbol, the previous processing output as the next input.
No=8
echo "obase=2; $no" | BC-output Result: 1000. Obase:out-base, Output binary.
no=1000
echo "obase=10;ibase=2; $no" | BC-Output: 8.ibase:in-base, input binary.
Note: Using BC parameters, we can specify the binary, complete the conversion between the binary value.
echo "sqrt (100)" | BC--Open square
echo "10^2" | BC-the second party
Shell script Programming {1} per day