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 13:00
Which part of the cpu accepts data?
Answers: 1
question
Computers and Technology, 23.06.2019 08:30
Helen's credit card has an apr of 15.32% and a grace period of 17 days and helen pays her balance in the full every month. if her last billing cycle ended on september 26, 2009, and she made her payment on october 11, 2009, did she owe any interest on her last statement's balance?
Answers: 3
question
Computers and Technology, 23.06.2019 15:30
Hey so i was just trying out some game hacks so i took a paste from online and built it in my visual studio and then suddenly my computer was working or clicking on stuff on its own am i hacked?
Answers: 1
question
Computers and Technology, 23.06.2019 22:30
You draw two cards from a standard deck of 52 cards, but before you draw the second card, you put the first one back and reshuffle the deck. (a) are the outcomes on the two cards independent? why?
Answers: 3
You know the right answer?
Reading Read the sections on parameters (Sobell, pages 460–470), control structures (Sobell, pages 4...
Questions
Questions on the website: 13722363