Problem

This project enables you to use the defining and evaluating operators to learn how they...

This project enables you to use the defining and evaluating operators to learn how they work. You begin by assigning a value to a variable and then view the contents of the variable you assigned. You then learn how to assign a variable that contains spaces, and you compare using single and double quotation marks to evaluate the contents of a variable. Finally, you use the back quote marks to execute a command and store the result in a variable.

To create a variable, and assign it a value:

1. Type DOG=Shepherd and press Enter.

You’ve created the variable DOG and set its value to Shepherd.

To see the contents of a variable:

1. Type echo DOG and press Enter.

You see the word “DOG.”

2. To see the contents of the DOG variable, you must precede the name of the variable with a $ operator. Type echo $DOG and press Enter.You see the word “Shepherd.” (See Figure 6-6.)

To use double quotation marks to set a variable to a string of characters containing spaces:

1. Type MEMO="Meeting will be at noon today" and press Enter.

2. Type echo $MEMO and press Enter.

You see the contents of the MEMO variable: Meeting will be at noon today.

To demonstrate how double quotation marks do not suppress the viewing of a variable’s contents, but single quotation marks do suppress the viewing:

1. Type echo '$HOME' and press Enter.

You see $HOME on the screen.

2. Type echo "$HOME" and press Enter.

You see the path of your home directory on the screen.

To demonstrate the back quote operator for executing a command:

1. Type TODAY=dateand press Enter. This command creates the variable TODAY, executes the date command, and stores the output of the date command in the variable TODAY. (No output appears on the screen.)

2. Type echo $TODAY and press Enter. You see the output of the date command that was executed in Step 1.

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