The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Requiring One and Only One Argument In A Bash Function

TODO: Pull subtitle into page object

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 `$1` otherwise it bails. Once it's past that check, it checks to see if an extra argument was passed in slot `$2` 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"`).

code_start_default_section code_end_default_section

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Requiring One and Only One Argument In A Bash Function

-- p

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 `$1` otherwise it bails. Once it's past that check, it checks to see if an extra argument was passed in slot `$2` and bails if that's the case.

-- p

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

-- code/
-- bash

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
}

-- /code


-- categories
-- Programming

-- metadata
-- date: 2021-05-04 00:00:00
-- id: 20eo2xld
-- status: published
-- type: post
-- SCRUBBED_NEO: false
-- site: aws