How to write Unix shell scripts with 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

FYI:

$1 = First positional parameter
$2 = Second positional parameter
.. = ..
$n = n th positional parameter

For more neat/flexible options, read this other thread: Using getopts to process long and short command line options

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)