Problem

In this project, you first compare the use of the sh -v and sh -x options in terms of th...

In this project, you first compare the use of the sh -v and sh -x options in terms of the output to the screen. Next, you practice debugging a shell script using sh -v.

To compare the results of the sh -v and sh -x options to debug a script:

1. Type sh -v colors (remember that colors is the script you created earlier in this chapter in which the favorite color is red), and press Enter.

2. Type green and press Enter.

3. Type red and press Enter. Notice that the command lines are printed.

4. Type sh -x colors and press Enter.

5. Type green and press Enter.

6. Type red and press Enter. Now, the command lines and arguments are displayed with a plus in front of them. Figure 6-16 illustrates the output of the sh -v and sh –x options.

To practice debugging a shell script:

1. Use the vi or Emacs editor to open the colors script for editing.

2. Go to the third line and delete the closing (right) bracket (]) after “red” and then exit, saving your change.

3. Type sh -v colors and press Enter.

4. Type green and press Enter. In the final line of output, you’ll see a note that shows the closing bracket is missing on line 3 of the colors script:

5. Use vi or Emacs to open the colors script and put the missing closing bracket back in.

6. Delete the echo command (only the word echo and not the entire command line) on the fourth line of the colors script. Close the editor and save your work.

7. Type sh -x colors and press Enter.

8. Type green and press Enter. Notice in the message that a command is missing on line 4:

9. Type red and press Enter to exit the script, or press Ctrl+z to exit.

10. Open the colors script using the vi or Emacs editor, retype the echo command on line 4, and close and save your work.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search