Bash is driving me nuts. I can't figure out why the following (nor any of the dozens of variations I've literally copied and pasted from examples) fails to work:#!/bin/bashecho $#function main {    if (( $# < 1 )); then        usage    fi    echo good}function usage {    echo Usage: $0 <outputdir>    exit 1}mainFor some reason the argument check fails every time, even when I pass an argument and can clearly see $# is set as expected.
Why is $# always 0 in my function?
bash;shell;parameter
This should work:#!/bin/bashset -xNARGS=$#function main {    if [ $NARGS -lt 1 ]; then        usage    fi    echo good}function usage {    echo Usage: $0 <outputdir>    exit 1}mainI left the set -x there on purpose. It's useful to debug these errors. If you don't pass any arguments to the main function, $# becomes 0 inside it (replace $NARGS with $# in the if condition to see this).