Requiring One and Only One Argument In A Bash Function

This is an example function you can add to your .rc files that requires exactly one argument to run. It checks to make sure there's an argument in slot [TODO: Code shorthand span ] otherwise it bails. Once it's past that check, it checks to see if an extra argument was passed in slot [TODO: Code shorthand span ] and bails if that's the case.

Quotes can be used if you need an argument with spaces in it (e.g. `my_command "roll tide"`).

function my_command () {
    if [ "$1" ]
    then
        if [ "$2" ]
        then
            echo "You passed too many arguments"
        else
            echo "Got: $1 - Do Stuff Here"
        fi
    else
        echo "You need to pass an argument"
    fi
}
~ fin ~