Verifying user input with lists

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 ...

Get Mastering Linux Shell Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.