In: Computer Science
CompTIA Linux+ Guide to Linux Certification (4th Edition)(Please do not do it in a mac and add pictures of the machine.)
Project 2-4 In this hands-on project, you use and protect shell metacharacters.
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 LNXrocks!.
2. At the command prompt, type date;who and press Enter to run the date command immediately followed by the who command. Use the information in Table 2-7 to describe the purpose of the ; metacharacter.
3. At the command prompt, type echo This is OK and press Enter to display a message on the terminal screen.
4. At the command prompt, type echo Don’t do this and press Enter. Which character needs to be protected in the previous command? Press the Ctrl and c keys together to cancel your command and return to a BASH shell prompt.
5. At the command prompt, type echo “Don’t do this” and press Enter. What is displayed on the terminal screen?
6. At the command prompt, type echo Don\’t do this and press Enter. What is displayed on the terminal screen?
7. At the command prompt, type echo $SHELL and press Enter to view the expansion of a variable using a shell metacharacter. What is displayed on the terminal screen? Next, type echo $TEST and press Enter to find out what happens when a variable that does not exist is used in a command. What is displayed?
8. At the command prompt, type echo You have $4.50 and press Enter. What is displayed? Why? Which character needs to be protected in the previous command? What are two different ways that you can protect this character from interpretation by the shell?
9. At the command prompt, type echo ‘You have $4.50’ and press Enter. What is displayed on the terminal screen? Did the single quotation marks protect this metacharacter from shell interpretation?
10. At the command prompt, type echo “You have $4.50” and press Enter. What is displayed on the terminal screen? Did the double quotation marks protect this metacharacter from shell interpretation?
11. At the command prompt, type echo You have \$4.50 and press Enter. What is displayed on the terminal screen? Did the backslash protect this metacharacter from shell interpretation?
12. At the command prompt, type echo My name is ‘whoami‘ and press Enter. What function do back quotes perform?
13. Type exit and press Enter to log out of your shell.
Below is the solution:
2. Answer:
john@Johns $ date;who
Thu Oct 22 09:11:45 IST 2020
john console Oct 22 09:00
john ttys000 Oct 22 09:00
semi colon will terminatet he command and when run the multiple command it will show the output of the each command related to the commad.
3. Answer:
john@Johns $ echo This is OK
This is OK
When we type the echo command it will print or display
4. Answer:
john@Johns $ echo Don’t do this
Don’t do this
No any charater needs to protect
5. Answer:
john@Johns $ echo “Don’t do this”
“Don’t do this”
Display the all the info with all the typed string, special character
6. Answer:
john@Johns $ echo Don\’t do this
Don’t do this
Neglet the forward slash
7. Answer:
john@Johns $ echo $SHELL
/bin/bash
Prints the shell name user is logged in
8. Answer:
john@Johns $ echo You have $4.50
You have .50
Terminal execute the echo command and prints, $4 will terminal execute as a command in terminal.
9. Answer:
john@Johns $ echo ‘You have $4.50’
‘You have .50’
Terminal execute the echo command and prints, $4 will terminal execute as a command in terminal in single quote string.
10. Answer:
john@Johns $ echo “You have $4.50”
“You have .50”
Terminal execute the echo command and prints, $4 will terminal execute as a command in terminal in double quote string.
11. Answer:
john@Johns $ echo You have \$4.50
You have $4.50
Terminal execute the echo command and prints, forward slash will terminal execute as a string in terminal.
12. Answer:
john@Johns $ echo My name is ‘whoami‘
My name is john
Prints the user name