What does it mean to move the parameter left? This parameter refers to the arguments that follow the script name when you run the script, you can use the $ #来获取参数的个数, use $* to get all the arguments, and the left side of the argument is this: there is a pointer to the first parameter of the parameter list, and the left shift means that each argument is read, The pointer points to the second parameter, as if the parameter were moved to the left, so that the value of each parameter can be read, which is especially common in the loop structure.
Here's an example:
#!/bin/bash# file name: test.shtot=0while [$#-gt 0]do echo ' parameter is ' $ #注意这里使用 ' to get the parameter value tot=$ (($tot + 1)) shift< c5/> #注意如果不使用shift时, there will be a dead loop done echo "altogether $tot parameters"
To run the test:
Shell Script--shift parameter left