Article From:


1.Variable assignment:Name=lbg    No spaces around the equal signName="Lebron James"   Double quotation marks are used for spaces in variable valuesEcho ${name} is safer with ${}Shopt-s -o nounset     Set "Statement before Use"2.Cancel variables:Unset releases memory for variables and functions3.Position parameters:${n}: The nth parameter entered ($0 denotes the script name)$#: Number of input parameters$@: All parameters entered$!:The last parameter entered$?:The return value of the previous command (used to determine the execution status of the command before execution in the script, any non-zero return indicates abnormal execution)4.Array:Declare-a Array=('ladawn' 'lbg' 'lbj')
5.Read-only variables:Declare-r N=10
        readonly N=10
6.Variables in a function:If local is not declared, the variables in the function are also global variables.If declared as local (local)var=200),Then the scope of the variable is only within the function.7.Quote:Double quotation marks: weak quotation, special symbols ($, \, `) still parse into special meanings.Single quotation mark: Strong quotation, all characters are literal meaning, no longer have special significance.8.Command Replacement:A=$(data)Or A=`data`,Indicates that the output of the data command is taken out and assigned to A9.bcOperation:Used for floating point calculation output. Use through pipes.Tatal=$(echo "34/15" | bc)
9.Numeric operations:Let"sum+=1"   Represents sum = sum+1
        let "j=sum%2"  Represents J = sum%2 


Link of this Article: Shell variable assignment

Leave a Reply

Your email address will not be published. Required fields are marked *