Shell special variables & #9758; location variables 1 and $0 get the file name of the current script, including the path. # Write a test script vimtest. sh # The content is as follows: dirname $0 basename $0 # execute bash $ (pwd)/test. sh # output:/home/janetest. sh2, $ n get the nth parameter of the script being executed, n = 1 .. 9, $0, current
Shell special Variables☞Location variable
1. $0 get the file name of the current script, including the path.
# Write a test script vim test. sh # The content is as follows: dirname $0 basename $0 # execute bash $ (pwd)/test. sh # output the following/home/janetest. sh
2. $ n: Obtain the nth parameter of the currently executed script, n = 1 .. 9, $0, which is the name of the current script. If n is greater than 9, use $ {10}
Echo 'echo '$ (seq-s "$" 1 5 | sed's/1/$1/')> test_n.shcattest_n.sh # Content: # echo $1 $2 $3 $4 $ 5bashtest_n.sh arg1 agr2 arg3 # output content: # arg1 agr2 arg3
3. $ * Get all Script Parameters
Echo 'echo $ * '> test _ *. shcattest _ *. sh # Content: # echo $ * bashtest _ *. sh 1 2 3 # output: #1 2 3
4. $ # obtain the number of all parameters of the script
Echo 'echo $ # '> test_j.shcattest_j.sh # Content: # echo $ # bashtest_j.sh 1 2 3 # output: #3