mardi 19 septembre 2017

Confirming the number of valid input arguments of a shell function

Assume a shell function my_function that expects to receive three valid input arguments:

my_function()
{
   echo "Three common metasyntactic variables are: $1 $2 $3"
}

I would like to include a test within my_function that assesses if the function has indeed received three input arguments and that none of these input arguments is empty.

$ my_function foo bar baz
Three common metasyntactic variables are: foo bar baz

$ my_function foo bar  # By default, no error message is given
Three common metasyntactic variables are: foo bar

How would I implement that?

Aucun commentaire:

Enregistrer un commentaire