Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with my Linux / Unix programming class. Please teach me how to write code following the procedure guidelines. If you can explain

I need help with my Linux / Unix programming class. Please teach me how to write code following the procedure guidelines. If you can explain all steps appreciate it. Need extra help understanding and executing steps 6, 7, 8. Thank you

Objective: 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 provides an introduction to positional parameters.

Procedure to Follow :

1. Use vim or cat to create a file named short with the following line in it: echo 'hi there'

2. Use cat to verify the contents of short and then try to execute it. Use ls l to display the permissions for short.

3. Use chmod to make the file executable, display the permissions for short, and try executing the file again.

4. Add a line that starts with #! to the beginning of short to make sure it is executed by bash.

5. Add a comment line to short that explains what the script does.

6. Within a shell script, the shell expands $1 (a variable called a positional parameter) 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 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 works properly.

8. 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 hap-pens when you give that filename as an argument to cptobak 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?

Outcome: This lab gives you practice writing and executing shell scripts.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago