I am trying to make a shell script which is designed to be run like this:
script.sh -t application
Firstly, in my script I want to check to see if the script has been run with the -t flag. For example if it has been run without the flag like this I want it to error:
script.sh
Secondly, assuming there is a -t flag, I want to grab the value and store it in a variable that I can use in my script for example like this:
FLAG="application"
So far the only progress I’ve been able to make on any of this is that $@ grabs all the command line arguments but I don’t know how this relates to flags, or if this is even possible.
You should read this getopts tutorial.
Example with
-aswitch that requires an argument :Like greybot said(
getopt!=getopts) :