Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Learning Objectives and Outcomes In this lab you will learn to write and execute a shell script that includes comments. You will use chmod to
Learning Objectives and Outcomes In this lab you will learn to write and execute a shell script that includes comments. You will use chmod to make the file that holds the script executable and include a line that starts with \#! in the script to make sure bash executes it. This lab also introduces positional parameters. Reading Read "Writing and Executing a Simple Shell Script" on pages 284-289 of Sobell. Procedure 1. Use vim or cat (see page 16 of this lab manual for instructions) to create a file named short with the following line in it: echo ' hi there comet' 2. Use cat to verify the contents of short and then try to execute it. Use lsl to display the permissions for short. Read the tip on Sobell, page 286. 3. Use chmod (Sobell) to make the file executable. Display the permissions for short. Try executing the file again. 4. Add a line that starts with \#! (Sobell) to the beginning of short to make sure it is executed by bash. 5. Add a comment line (Sobell) to short that explains what the script does. 6. Within a shell script, the shell expands \$1 (a variable called a positional parameter; Sobell) to the first argument on the command line the script was called with. Write and execute a script named first that displays (sends to standard output) the first argument on the command line it was called with. Include the \#! line and a comment. Remember to make the file executable. 7. Write a shell script named cptobak that copies the file named by its first argument to a file with the same name with the filename extension of .bak. Thus, if you call the script with the argument first (and a file named first exists in the working directory), after the script runs you would have two files: first and first.bak. Demonstrate that the script eptobak works properly. Read the caution titled "Always quote positional parameters" on page 462 of Sobell. Use touch to create a file whose name has a SPACE in it. What happens when you give that filename as an argument to eptobak from the previous step? Modify the cptobak script from the previous step by quoting the positional parameters in the cp line. Now what happens when you use the script to make a copy of a file with a SPACE in its name
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started