Calling a function with empty argument
by Faki from LinuxQuestions.org on (#5SQE6)
I want to allow a usage function to be called with an empty variable or with no variable at all.
For instance, being able to use
Code:arg=""
heading-usage $argand
Code:heading-usageHere is the function listing. Is it adequate for calling the `(*)` condition when `arg` is empty or not present? Had noticed that `$#` becomes `1` if `arg` is empty, forcing be to ditch the condition `(( $# == 0 ))` that I initially used for the situation when `arg` is empty.
Code:heading-usage ()
{
case $1 in
(1)
printf '%s\n' " -v VB, -v=VB, -vVB"
printf '%s\n' " -h, --help, -u, --usage"
;;
(2)
printf '%s\n' "Additional Information"
;;
(*)
printf '%s\n' "Display a heading"
;;
esac
}
For instance, being able to use
Code:arg=""
heading-usage $argand
Code:heading-usageHere is the function listing. Is it adequate for calling the `(*)` condition when `arg` is empty or not present? Had noticed that `$#` becomes `1` if `arg` is empty, forcing be to ditch the condition `(( $# == 0 ))` that I initially used for the situation when `arg` is empty.
Code:heading-usage ()
{
case $1 in
(1)
printf '%s\n' " -v VB, -v=VB, -vVB"
printf '%s\n' " -h, --help, -u, --usage"
;;
(2)
printf '%s\n' "Additional Information"
;;
(*)
printf '%s\n' "Display a heading"
;;
esac
}