Hack Forums
[Shell] [Bash Scripting] Good way to evaluate script arguments - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Shell] [Bash Scripting] Good way to evaluate script arguments (/showthread.php?tid=6026203)



[Bash Scripting] Good way to evaluate script arguments - netWalker - Nov 19, 2019

This is just a good way to evaluate arguments passed to a script that I've been using.

Code
#!/bin/bash
while [ $# != 0 ]
do
    case $1 in
        -a)
            var1=$2
             shift 2
            ;;
        -b)
            var2=$2
            shift 2
            ;;
        -c)
            var3=$2
            shift 2
            ;;
          *)
            echo "invalid argument $1"
            exit 1
    esac
done