1. $0 Gets the file name of the current script, including the path.
Copy the codeThe code is as follows:
#Writing a test script
vim
#The content is as follows
dirname$0
basename$0
#Execute it
bash$(pwd)/
#Output as follows
/home/jane
2. $n Gets the nth parameter of the currently executing script, n=1..9, $0, which is the current script name. If n is greater than 9, use ${10}
Copy the codeThe code is as follows:
echo'echo '$(seq-s " $"1 5|sed's/1/$1/') > test_n.sh
cattest_n.sh
#The content is as follows
#echo $1 $2 $3 $4 $5
bashtest_n.sh arg1 agr2 arg3
#Output content:
#arg1 agr2 arg3
3. $* Get all parameters of the script
Copy the codeThe code is as follows:
echo'echo $*'>test_*.sh
cattest_*.sh
#The content is as follows:
#echo $*
bashtest_*.sh 1 2 3
#Output:
#1 2 3
4. $# Get the number of all parameters of the script
Copy the codeThe code is as follows:
echo'echo $#'>test_j.sh
cattest_j.sh
#The content is as follows:
#echo $#
bashtest_j.sh 1 2 3
#Output:
#3