Question
8. Write and run a simple shell script named echomyvar that displays the PID (Sobell, page 480) of the process running the script and value
8. Write and run a simple shell script named echomyvar that displays the PID (Sobell, page 480) 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 486, 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 echomyvar. 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 485) builtin in the interactive shell to place myvar in the environment and run echomyvar. (You can export myvar without 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 display the export attribute for myvar. The export builtin and declare x perform the same function. Use export n (Sobell, page 486) to unexport myvar. Show that myvar is a shell variable but is no longer in the environment. Use the unset (Sobell, page 314) builtin to remove myvar. Show that myvar is not available in the interactive shell or in the environment. Deliverables This lab gives you practice using positional parameters, comments, temporary files, and control structures in shell scripts that query the user and read information the user enters. It also has you work with PIDs, the export builtin, and the environment.
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