In this script, we will ensure that a value has been supplied to the first positional parameter. We can modify the hello2.sh script that we created in Chapter 1, The What and Why of Scripting with Bash, to check for user input before displaying the hello text.
You can copy the hello2.sh script to hello4.sh, or simply create a new script from scratch. There will not be a lot of typing and the script will be created as $HOME/bin/hello4.sh, as shown:
We can ensure that the script is executable by using the following command:
$ chmod +x $HOME/bin/hello4.sh
We can then run the script with or without arguments. The test statement is looking for the $1 variable to be zero bytes. If it is, then we will not see the hello statement; otherwise, it will print the hello message. In simple terms, we will see the hello message if we supply a name.
The following...