More syntax errors
A fundamental problem with shell scripts is syntax errors don't usually show up until the line with the problem is parsed by the interpreter. Here's a common error that I still find myself doing more than I should. See if you can locate the problem by just reading the script:
Chapter 9 - Script 3
#!/bin/sh # # 6/7/2017 # echo "Chapter 9 - Script 3" if [ $# -ne 1 ] ; then echo "Usage: script3 parameter" exit 255 fi parm=$1 echo "parm: $parm" if [ "$parm" = "home" ] ; then echo "parm is home." elif if [ "$parm" = "cls" ] ; then echo "parm is cls." elif [ "$parm" = "end" ] ; then echo "parm is end." else echo "Unknown parameter: $parm" fi echo "End of script3" exit 0
Here's the output:
Did you find my mistake? When I code an if...elif...else
statement, I tend to copy and paste the first if
statement. I then prepend elif
to the next statement but forget to remove the if
. This gets me almost every time.
Look at how I ran this script. I started first with just the name...