Skip to main content
2 of 2
Correct misunderstanding on passing variables

This should work:

#!/bin/bash set -x NARGS=$# function main { if [ $NARGS -lt 1 ]; then usage fi echo good } function usage { echo "Usage: $0 <outputdir>" exit 1 } main 

I 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).