Problem

In this hands-on project, you create and use an alias, as well as view and change existi...

In this hands-on project, you create and use an alias, as well as view and change existing shell variables. In addition to this, you export user-defined variables and load variables automatically upon shell startup.

1. Switch to a command-line terminal (tty2) by pressing Ctrl+Alt+F2 and log in to the terminal using the user name of root and the password of secret.

2. At the command prompt, type set | less and press Enter to view the BASH shell environment variables currently loaded into memory. Scroll through this list using the cursor keys on the keyboard. When finished, press q to quit the less utility.

3. At the command prompt, type env | less and press Enter to view the exported BASH shell environment variables currently loaded into memory. Scroll through this list using the cursor keys on the keyboard. Is this list larger or smaller than the list generated in Step 2? Why? When finished, press q to quit the less utility.

4. At the command prompt, type PS1="Hello There:" and press Enter. What happened and why? Next, type echo $PS1 at the command prompt and press Enter to verify the new value of the PS1 variable.

5. At the command prompt, type exit and press Enter to log out of the shell. Next, log in to the terminal using the user name of root and the password of secret. What prompt did you receive and why? How could you ensure that the “Hello There:” prompt occurs at every login?

6. At the command prompt, type vi .bash_profile and press Enter. At the bottom of the file, add the following lines. When finished, save and quit the vi editor.

echo –e "Would you like a hello prompt? (y/n) -->\c"

read ANSWER

if [ $ANSWER = "y" ]

then

PS1="Hello There: "

fi

Explain what the preceding lines will perform after each login.

7. At the command prompt, type exit and press Enter to log out of the shell. Next log in to the terminal using the user name of root and the password of secret. When prompted for a hello prompt, type y and press Enter. What prompt did you receive and why?

8. At the command prompt, type exit and press Enter to log out of the shell. Next, log in to the terminal using the user name of root and the password of secret. When prompted for a hello prompt, type n and press Enter to receive the default prompt.

9. At the command prompt, type MYVAR="My sample variable" and press Enter to create a variable called MYVAR. Verify its creation by typing echo $MYVAR at the command prompt and press Enter.

10. At the command prompt, type set | grep MYVAR and press Enter. Is the MYVAR variable listed? Why?

11. At the command prompt, type env | grep MYVAR and press Enter. Is the MYVAR variable listed? Why?

12. At the command prompt, type export MYVAR and press Enter. Next, type env | grep MYVAR at the command prompt and press Enter. Is the MYVAR variable listed now? Why?

13. At the command prompt, type exit and press Enter to log out of the shell. Next, log in to the terminal using the user name of root and the password of secret.

14. At the command prompt, type echo $MYVAR and press Enter to view the contents of the MYVAR variable. What is listed and why?

15. At the command prompt, type vi .bash_profile and press Enter. At the bottom of the file, add the following line. When finished, save and quit the vi editor. export MYVAR="My sample variable"

16. At the command prompt, type exit and press Enter to log out of the shell. Next, log in to the terminal using the user name of root and the password of secret.

17. At the command prompt, type echo $MYVAR and press Enter to list the contents of the MYVAR variable. What is listed and why?

18. At the command prompt, type alias and press Enter. What aliases are present in your shell?

19. At the command prompt, type alias asample="cd /etc ; cat hosts ; cd ~ ; ls –F" and press Enter. What does this command do?

20. At the command prompt, type asample and press Enter. What happened and why? What environment file could you add this alias to so that it is executed each time a new BASH shell is created?

21. Type exit and press Enter to log out of your shell.

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
Solutions For Problems in Chapter 7