I’m writing a bash script that needs to loop over the arguments passed into the script. However, the first argument shouldn’t be looped over, and instead needs to be checked before the loop.
If I didn’t have to remove that first element I could just do:
for item in "$@" ; do
#process item
done
I could modify the loop to check if it’s in its first iteration and change the behavior, but that seems way too hackish. There’s got to be a simple way to extract the first argument out and then loop over the rest, but I wasn’t able to find it.
Use
shift.Read
$1for the first argument before the loop (or$0if what you’re wanting to check is the script name), then useshift, then loop over the remaining$@.