Problem

This project provides your first introduction to using an if statement in a shell script...

This project provides your first introduction to using an if statement in a shell script and demonstrates decision logic. In the first set of steps, you create a script using a basic if statement. Then, in the second set of steps, you modify your script to include an if statement nested within an if statement.

To demonstrate the if statement as well as to implement decision logic:

1. Type vi veg_choice and press Enter.

2. Type i to switch to vi’s insert mode.

3. Type the following lines:

4. Be certain your editing session looks like the one in Figure 6-10. Press Esc to switch to vi’s command mode.

5. Type :x and press Enter to save the file and exit vi.

6. Make the script executable by typing chmod ugo+x veg_choice and pressing Enter. Next, run the script by typing ./veg_choice and pressing Enter (if you are continuing the same terminal session from Hands-on Project 6-5, you don’t need to type “./”, because the PATH environment variable stil contains the current working directory.)

7. When asked to enter the name of your favorite vegetable, answer broccoli.

8. Run the script again and respond with corn or some other vegetable name.

To practice writing a nested if statement:

1. Open the veg_choice file in vi or Emacs.

2. Edit the file so it contains the following lines. (Code has been added to the else part of the original if statement. See the lines in bold.)

3. Execute the script and respond with carrots when asked for your favorite vegetable. You should see the response “Carrots are great for you.”

4. Type clear and press Enter to clear the screen for the next project.

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