sh script options 1

sh script options

$ cat stack.sh 
#!/bin/sh
if  [[ $1 = "-o" ]]; then
    echo "Option -o turned on"
else
    echo "You did not use option -o"
fi

$ bash stack.sh -o
Option -o turned on

$ bash stack.sh
You did not use option -o

Here is what the above code is Doing:
1. The first line of the script is a shebang. It tells the shell what program to use to run the script.
2. The second line is an if statement. It checks if the first argument passed to the script is equal to -o.
3. If the first argument is equal to -o, then the script prints “Option -o turned on”.
4. If the first argument is not equal to -o, then the script prints “You did not use option -o”.

Similar Posts