I have a script with this:
login {
# checking parameters -> if not ok print error and exit script
if [ $# -lt 2 ] || [ $1 == '' ] || [ $2 == '' ]; then
echo "Please check the needed options (username and password)"
echo ""
echo "For further Information see Section 13"
echo ""
echo "Press any key to exit"
read
exit
fi
} # /login
But I really dont know what the $#
means on the third line.
The pound sign counts things.
$#
, it's the number of positional parameters, like $1
, $2
, $3
. (Not counting $0
, mind you.)${#var}
, it's the number of characters in the expansion of the parameter. (String length)${#var[@]}
, it's the number of elements in the array. Since bash arrays are sparse, this can be different from the index of the last element plus one.It's the number of arguments passed.
You can read it here, search for "Detecting command line arguments"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With