[[email protected] mybash]# vim.hello.sh #! /bin/sh# This isA example bash Scriptecho"Hello world! \ n"Echo"parameter num: $#"Echo"script ' s name is $"Echo"parameter 0: $"Echo"parameter 1: $"if[$#-ge1] # Note: square brackets [] within the description of the content must be left open before and after, or wrong. Then IDX=$1#将变量idx赋值为参数 $1, the declaration of a variable cannot have a space, that is, there is no space between the variable name and the equal sign. Elseidx=3#ifNo parameter1, let it bedefaultValue3. Fi while[$idx-GT0 ] DoEcho"idx is $idx" Let"idx=idx-1"Sleep1Datedoneexit0
$# represents the number of arguments passed to a script or function
$ A indicates the file name of the current script
$n arguments passed to the script or function. N is a number that represents the first parameter, and the second argument is $
-GT the number to the left is greater than or equal to the number on the right, greater than true
-lt the number to the left is less than or equal to the number on the right, less than true
Variable+if+while