Inside my bash script, I would like to parse zero, one or two parameters (the script can recognize them), then forward the remaining parameters to a command invoked in the script. How can I do that?
相关问题
- JQ: Select when attribute value exists in a bash a
- bash print whole line after splitting line with if
- “command not found” errors in expect script execut
- grep using grep results
- softlinks atime and mtime modification
相关文章
- Check if directory exists on remote machine with s
- Reverse four length of letters with sed in unix
- Compile and build with single command line Java (L
- Launch interactive SSH bash session from PHP
- BASH: Basic if then and variable assignment
- Bash script that creates a directory structure
- Test if File/Dir exists over SSH/Sudo in Python/Ba
- How can I create a “tmp” directory with Elastic Be
bash supports subsetting parameters (see Subsets and substrings), so you can choose which parameters to process/pass like this:
open new file and edit it: vim r.sh
run it:
the result is:
Use the
shift
built-in command to "eat" the arguments. Then call the child process and pass it the"$@"
argument to include all remaining arguments. Notice the quotes, they should be kept, since they cause the expansion of the argument list to be properly quoted.bash uses the shift command:
e.g. shifttest.sh:
shifttest.sh 1 2 3 produces