I would like to have my script accepting variable arguments. How do I check for them individually?
For example
./myscript arg1 arg2 arg3 arg4
or
./myscript arg4 arg2 arg3
The arguments can be any number and in any order. I would like to check if arg4 string is present or not irrespective of the argument numbers.
How do I do that?
Thanks,
The safest way — the way that handles all possibilities of whitespace in arguments, and so on — is to write an explicit loop:
If you’re certain your arguments won’t contain spaces — or at least, if you’re not particularly worried about that case — then you can shorten that to: