For one of my CLIs, I needed to remove the first argument from the argument list and forward the rest to a next process. In this example, my shell script is called
cli_process and given arguments
arg3, I want to execute
# Documentation on @ # https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#index-_0040 # Documentation on shift [n] # https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#index-shift # Why quoting the argument is "necessary": # https://stackoverflow.com/questions/4824590/propagate-all-arguments-in-a-bash-shell-script/4824637#4824637 # eats 1 argument shift 1 # forwards the rest to "forward_process" forward_process "$@"
Originally posted as a gist, by myself.
.bat files support a similar token:
%*, which is equivalent to
SHIFT command, unlike the bash equivalent
shift, doesn't modify this special token. There are various solutions that will attempt to eat the first
n parameters, but all of them have edge-cases in which they don't properly work. Should you need this in windows, I recommend you write out the arguments manually
%3 (and skip
Here you can find some Windows solutions, but make sure you check the comments underneath each one:
- StackOverflow (935609): batch parameters: everything after %1
- StackOverflow (761615): Is there a way to indicate the last n parameters in a batch file?