23 esac There are at least three (Free php web host) errors

23 esac There are at least three errors in this script. See if you can find them. If this script is in a file called buggy2.sh, executing it produces the following output: Deleting old backups, please wait… Done. Make backup (y/n)? Entering y at the prompt produces the following error: ./buggy3.sh: syntax error at line 21: ‘)’ unexpected Due to a bug in the script, you can’t make a backup, and you have already lost your previous backup. As you can imagine, this is a very bad situation. The reason the script gets that far before detecting an error is that the shell reads and executes each line of a shell script individually, just like it does on the command line. Here the shell reads and executes lines until it encounters a problem. By using the -n option, the script does not execute. Instead, each line is checked to make sure that it has the correct syntax. This helps you avoid the situation encountered by running the buggy2.sh script because only the error is reported: ./buggy2.sh: syntax error at line 21: ‘)’ unexpected Using Verbose Mode Now that you know why syntax checking should be employed, you can track down the source of the problem. Looking at line 21 of buggy2.sh 21 [nN]|[Nn][Oo]) it is hard to see why the shell thinks the parenthesis ) is unexpected. Sometimes knowing where a syntax error occurs is not enough–you have to know the context in which the error occurs. The shell provides you with the -v ( v as in verbose) debugging mode in order to check the context in which a syntax error occurs. When this option is specified, the shell prints each line of a script as it is read. If you issue the -v option by itself, every line in the script will execute. Because you want to check the syntax, you combine the -n and -v options as follows: $ /bin/sh -nv script arg1 arg2 … argN If you execute buggy2.sh with the debugging options
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Leave a Reply