I am writing a shell program that takes in three arguments:
- an integer to determine the function of the program
- a file used by the program
The command is of the form myProgram num file. However, I want the program to output an error if the command only has 0, 1, or more than 2 arguments. That is, if I type “myProgram”, “myProgram num”, or “myProgram num file anotherWord”, an error will be printed to the screen. Does anyone know how I could implement this into my existing code?
The built-in variable
$#contains the number of arguments that were passed to the script. You use this to check if there are enough arguments like so: