Stack Overflow archive
0 score

For loop in Bash to take action on just first positional arg

score
0
question views
85
license
CC BY-SA 3.0

There are many ways you could handle this. You could process $var1 before the loop or add some condition like the following:

bash
handled_first=false
for arg in "$var1" "$var2" "$var3" "$varN" ; do 
  if ! $handled_first; then
    # do stuff
    handled_first=true
    continue
  fi
  # other stuff
done

Originally posted on Stack Overflow. Public user contributions are licensed under Creative Commons Attribution-ShareAlike.