#!/bin/bash

#-----
# more-if-play
#
# playing with if statements some more
#
# by: Sharon Tuttle
# last modified: 2022-09-14
#-----

echo "At beginning: \$# is: $#"

# HEY all of -eq and = and == work?!

if [ $# -eq 0 ]
then
    echo "using -eq, called with NO command-line arguments"
fi

if [ $# = 0 ]
then
    echo "using =, called with NO command-line arguments"
fi

if [ $# == 0 ]
then
    echo "using ==, called with NO command-line arguments"
fi

# if no command line arguments are given, ask for one

if [ $# -eq 0 ]
then
    echo -n "Enter something: "
    read input
else
    input=$1
fi

# using the elif syntax; note that extra fi instances are
#    NOT needed here

if [ $# -eq 0 ]
then
    echo "called with NO arguments"
elif [ $# = 1 ]
then
    echo "called with ONE argument"
else
    echo "called with MORE THAN ONE argument"
fi

# if you nest the if statement, it MUST have a fi!

if [ $# -eq 0 ]
then
    echo "called with NO arguments"
else if [ $# = 1 ]
then
    echo "called with ONE argument"
else
    echo "called with MORE THAN ONE argument"
fi
fi

# to me, in this case, this indentation looks better
#     and I'm less likely to omit the needed fi:

if [ $# -eq 0 ]
then
    echo "called with NO arguments"
else
    if [ $# = 1 ]
    then
        echo "called with ONE argument"
    else
        echo "called with MORE THAN ONE argument"
    fi
fi

echo "\$input: [$input]"