Optional argument in sh script

I wonder if there is any way to execute script with argument that can be optional. For example

./script (optional parameter X) path

So typing ./script /Users/name/Documents would execute certain function (I assume that if statement will be crucial) and ./script X Users/mcichecki/Documents will execute another function. I was trying to do it with optional arguments and it didn't work:

    ARG1=${1:-R}

    if [ "$1" = "X" ];
    then
        first_function
    else
        second_function
    fi


ANSWERS:


If the optional argument were last you could use default values. It doesn't work so well when it is first.

Use $# to check the number of arguments that were passed in.

case $# in
    1) ARG1=-R; ARG2=$1;;
    2) ARG1=$1; ARG2=$2;;

    *) echo "Usage: $0 [parameterX] path" >&2; exit 1;;
esac


 MORE:


 ? Optional argument in sh script
 ? cleaning out optional arguments and passing it out shell script
 ? How to denote that a command line argument is optional when printing usage
 ? Shell script with options and argument - Update
 ? Running C Executable With Arguments As C Executable From Shell Script
 ? UNIX Shell scripting/Menu
 ? Find and replace: \'
 ? Find and replace: \'
 ? Find and replace: \'
 ? replace with sed on Mac OS X Leopard doesn't do what expected