Based on comments, my understanding is that you want to discard (or store somewhere) the first argument, and then use the rest of the arguments as arguments to another script or command that you are calling from within your script.
If that's so, you can do it pretty easily, and you don't need to set a variable (FLAGS
or anything else) to pass the script's parameters to the command within your script. See the following example:
#!/bin/bash
set -x
original_first_arg="$1" # Use this line if you need to save the value to use later.
shift
mycommand "$@"
The shift
command is a bash
builtin. By itself (without giving it any number), it just throws away the script's first argument (positional parameter). From the manpage:
shift [n]
The positional parameters from n+1 ... are renamed to $1 ....
Parameters represented by the numbers $# down to $#-n+1 are
unset. n must be a non-negative number less than or equal to
$#. If n is 0, no parameters are changed. If n is not given,
it is assumed to be 1. If n is greater than $#, the positional
parameters are not changed. The return status is greater than
zero if n is greater than $# or less than zero; otherwise 0.
Then "$@"
expands to exact parameters you gave the script, minus the first one $1
since that was thrown away by the shift
command.
Further reading:
FLAGS
, is it possible that what you're actually trying to do here is parse options in your script? – Wildcard Dec 24 '15 at 09:23test
is both a shell builtin and a standard utility (trytype -a test
): you should choose a different name for your program. – glenn jackman Dec 24 '15 at 13:51