subject

Reading Read the sections on parameters (Sobell, pages 460–470), control structures (Sobell, pages 419–435), and environment (Sobell, pages 471–474).

Procedure

The shell expands $0 to the name of the calling program (Sobell, page 461), $1–$n to the individual command-line arguments (positional parameters; Sobell, page 462), $* (Sobell, page 465) to all positional parameters, and $# (Sobell, page 466) to the number of positional parameters.

1. Write a script named all that displays (sends to standard output) the name of the calling program, the number of positional parameters, and a list of positional parameters. Include the #! line (Sobell, page 287) and a comment (Sobell, page 288). Remember to make the file executable (Sobell, page 100). Test the script with 0, 1, and 5 positional parameters.

2. Make a symbolic link (Sobell, page 113) named linkto to the all script you wrote in the previous step. Call linkto with two arguments. What does the script report as the name it was called as?

3. Write a script named myname that uses echo (most of the examples in Chap- ter 10 use this utility) to prompt the user with Enter your name: , reads into a variable the string the user types in response to the prompt, and then dis- plays Hello followed by the string the user typed. When you run the program it should look like this: $ ./myname Enter your name: Max Wild Hello Max Wild

4. Rewrite myname from the previous step, calling it myname2. Have this version of the program prompt the user for a string, but instead of displaying Hello and the string on the screen (sending it to standard output) redirect the output so the program writes only the string the user entered (and not Hello) to the temporary file named PID. name where PID is the process ID number (Sobell, page 467) of the process running the script. Display the contents of the PID. name file.

5. Write and run a script named looper that uses the for (Sobell, page 434) control structure to loop through the command-line arguments and display each argument on a separate line.

6. Rewrite looper from the previous step, calling it looper2. Have this version of the program use the for...in control structure (Sobell, page 432) to perform the same task.

7. Write a script named ifthen that prompts the user with >> and reads a string of text from the user. If the user enters a nonnull string, the script displays You entered: followed by the string; otherwise it displays Where is your input?. Use an if...then...else control structure (Sobell, page 424) to imple- ment the two-way branch in the script. Use the test (Sobell, pages 420 and 978) builtin to determine if the user enters a null string. What do you have to do to avoid getting an error message when you prompt with >>? (There are several ways to construct the test statement.)

8. Write and run a simple shell script named echomyvar that displays the PID (Sobell, page 467) of the process running the script and value of the variable named myvar. Display the PID of the interactive shell you are working with. What is the value of the variable within the process running the shell script? Are the interactive shell and the shell running the script run by the same or different processes (do they have the same PID)?

$ cat echomyvar

echo The PID of this process is $$

echo The value of myvar is: $myvar

$ echo $$

2651

$ ./echomyvar

The PID of this process is 4392

The value of myvar is:

The example near the top of Sobell, page 473, demonstrates a way to put a variable in the environment of a script you are calling without declaring the variable in the interactive shell you are running. Use this technique to assign a value to myvar, place it in the environment of echomyvar, and run echo myvar. After running the script, is myvar set in the interactive shell?

On the command line, assign a value to the variable named myvar and then run echomyvar again. Which value does the script display?

Use the export (Sobell, page 472) builtin in the interactive shell to place myvar in the environment and run echomyvar. (You can export myvar with out assigning a new value to it.) Did the script display the value of myvar this time?

Is the PID of the interactive shell the same or different from the PID of the script?

Call export without an argument and send the output through grep to dis- play the export attribute for myvar. The export builtin and declare –x perform the same function.

Use export –n (Sobell, page 473) to unexport myvar. Show that myvar is a shell variable but is no longer in the environment.

Use the unset (Sobell, page 304) builtin to remove myvar. Show that myvar is not available in the interactive shell or in the environment.

Deliverables Please submit the contents of scripts written, the command line calls that you make and the answers to any questions asked

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 22:30
Jason needs to learn a new web tool. he went through his books to understand more about it. now he wants hands-on experience with using that tool. what would him? jason can use websites where workspace is provided to test the results of your code.
Answers: 2
question
Computers and Technology, 22.06.2019 23:30
For her science class, elaine is creating a presentation on weather in the united states. she wants to make the presentation beautiful and interesting by drawing simple cloud or wave shapes. which is the best way for elaine to draw these shapes?
Answers: 1
question
Computers and Technology, 23.06.2019 01:30
In deadlock avoidance using banker’s algorithm, what would be the consequence(s) of: (i) a process declaring its maximum need as maximum possible for each resource. in other words, if a resource a has 5 instances, then each process declares its maximum need as 5. (ii) a process declaring its minimum needs as maximum needs. for example, a process may need 2-5 instances of resource a. but it declares its maximum need as 2.
Answers: 3
question
Computers and Technology, 23.06.2019 06:00
Which statement is true of web-based social media? a.they allow consumers to interact with and update content. b.they cannot be updated easily, as compared to print media. c.they are expensive to produce and maintain, as compared to print and television. d.they can exist independent of the internet.
Answers: 1
You know the right answer?
Reading Read the sections on parameters (Sobell, pages 460–470), control structures (Sobell, pages 4...
Questions
question
Health, 22.03.2021 18:40
question
Mathematics, 22.03.2021 18:40
question
Mathematics, 22.03.2021 18:40
question
Mathematics, 22.03.2021 18:40