2

I have shell script that pass arguments to script, like this:

script.sh argA argB arg1 arg2 arg3 argN

ArgA and ArgB consider for name and family.

Arg1 ... argN are phone numbers. (Maybe 1 to N depend to user input)

Here is my script:

for var in "$@"
do
    echo "$var"
done

"$@" pass all arguments, but I need do this from third argument and use ArgA, ArgB somewhere else in my script.

Any recommendation?

4

You can use shift to move down the line of parameters.

name=$1
family=$2
shift 2

for var in "$@"
do
  something_with "$var"
done

shift 2 will essentially remove parameters 1 and 2 and restart at 3 (arg1).

  • That’s exactly what I want, Thanks ;) – Mehrdad Aug 16 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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