Accessing shell script arguments by index
问题 I'm sure this is a no-brainer when you're into shell programming. Unfortunately I'm not and I'm having a pretty hard time ... I need to verify arguments passed to a shell script. I also want to store all parameters passed in an array as I need further separation later. I have an argument "-o" which must be followed by either 0 or 1. Thus, I want to check if the following argument is valid. Here's what I tried: # Loop over all arguments for i in "$@" do # Check if there is a "-" as first