Originally Posted by SecureScript
Ok thanks kbscores, that is the correct If statement, however when I run it I get an error "Too many arguments" on the line starting with the If statement:
if [ $userchoice = 0]
There needs to be a space before the final bracket. Remember, [ is a command
, and all the pieces following the initial bracket are arguments
to that command which need to be separated by whitespace in order for the shell to parse it correctly. In this case "0]" is treated as a single argument, meaning it can't find the closing bracket and thinks that everything following it is also part of the test.
In addition, always quote your variable substitutions
, particularly inside [..]
. A variable containing multiple words would otherwise be seen as multiple arguments.
More on argument processing here:
Finally, you can avoid most of these problems in bash by using the new [[ test keyword
But in fact, numeric comparisons like this are better done with the ((..)) arithmetic evaluation
if (( userchoice == 0 )) ; then