Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I get a cmd line like:

myscript param1 param2 param3 param4 param5 param6 ... (so on)

How can I save a string consisting of parameters starting from some specific one? The $@ gives me the whole command line concatenated. What I need is to get a string starting like "param4 param5 param6 ... (so on)".

share|improve this question
up vote 4 down vote accepted

You have to take aways the uninteresting arguments by:

shift 3
share|improve this answer

You can use a variant on array slicing to do this:

args1to3="${*:1:3}"  # Three arguments starting from $1
args4on="${*:4}"     # The arguments starting from $4

BTW, this may not be what you want, because it just sticks the arguments together with spaces between them; if any of the arguments also contain spaces, it'll lose track of which spaces were inside arguments and which were between them (see BashFAQ #50). If you want to be able to keep them straight, use an array instead:

args1to3=("${@:1:3}")   # Three arguments starting from $1, as an array
args4on=("${@:4}")      # The arguments starting from $4, as an array

othercmd "${args1to3[@]}"             # Pass the first 3 arguments intact
for somearg in "${args4on[@]}"; do    # Process args 4 on, one at a time
  othercmd2 "$somearg"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.