Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Provide the one-line commands to perform the tasks below (Bash Shell) Create the

ID: 3665108 • Letter: P

Question

Provide the one-line commands to perform the tasks below (Bash Shell)

Create the var1 shell variable, and initialize it to twenty:

Create the var2 shell variable, and initialize it to 21:

Create the var3 shell variable, and initialize it to temp:

Display the values of all three variables:

Display the list of local shell variables, and determine if either var1, var2, or var3 is in the listing:

Display the list of environmental variables, and determine if either var1, var2, or var3 is in the listing:

Use the export command to make var1 and var3 environmental variables.

Display the list of environmental variables, and determine if either var1 or var3 is in the listing.

Remove the var3 variable with the unset command.

Display the list of local shell variables, and determine if either var1, var2, or var3 is in the listing:

Display the list of environmental variables, and determine if either var1, var2, or var3 is in the listing:

Start a child tcsh shell:

In the new (child) shell, display the list of local shell variables, and determine if either var1 or var2 is in the listing:

In the new (child) shell, display the list of environmental variables, and determine if either var1 or var2 is in the listing:

Explanation / Answer

Create the var1 shell variable, and initialize it to twenty:
var1 = twenty
Create the var2 shell variable, and initialize it to 21:
var2=21
Create the var3 shell variable, and initialize it to temp:
var3=temp
Display the values of all three variables:
echo $var1 $var2 $var3
Display the list of local shell variables, and determine if either var1, var2, or var3 is in the listing:
  
set | grep "var1|var2|var3"

set command without arguements displays all local shell variables and then we pipe with grep to search for var1, var2
and var3
  
Display the list of environmental variables, and determine if either var1, var2, or var3 is in the listing:
env | grep "var1|var2|var3"

env is used to list environmental variables, use grep to search for the variable names. Since the variables are local,
they are not listed in environment variables list
  
Use the export command to make var1 and var3 environmental variables.
export var1=twenty
export var3=temp
Display the list of environmental variables, and determine if either var1 or var3 is in the listing.
env | grep "var1|var3"

now var1 and var3 should be listed.
  
Remove the var3 variable with the unset command.
unset var3
  
Display the list of local shell variables, and determine if either var1, var2, or var3 is in the listing:
set | grep "var1|var2|var3"

now only var1 and var2 get displayed. var3 is not listed
  
Display the list of environmental variables, and determine if either var1, var2, or var3 is in the listing:

env | grep "var1|var2|var3"

now only var1 is listed in environment variables. var3 is not listed.
  
Start a child tcsh shell:
tcsh

In the new (child) shell, display the list of local shell variables, and determine if either var1 or var2 is in the listing:
set | grep "var1=|var2="

variables var1 and var2 are not listed.
  
In the new (child) shell, display the list of environmental variables, and determine if either var1 or var2 is in the listing:
env | grep "var1=|var2="

var1 is listed as it is exported.

=======
output


bash-3.2$ var1=twenty
bash-3.2$ var2=21
bash-3.2$ var3=temp
bash-3.2$ echo $var1 $var2 $var3
twenty 21 temp
bash-3.2$ set | grep "var1=|var2=|var3="
var1=twenty
var2=21
var3=temp
bash-3.2$ env | grep "var1=|var2=|var3="
bash-3.2$ export var1=twenty
bash-3.2$ export var3=temp
bash-3.2$ env | grep "var1=|var3="
var1=twenty
var3=temp
bash-3.2$ unset var3
bash-3.2$ set | grep "var1=|var2=|var3="
var1=twenty
var2=21
bash-3.2$ env | grep "var1=|var3="
var1=twenty
bash-3.2$ tcsh
[amoeba-2:] raji% set | grep "var1=|var2="
[amoeba-2:] raji% env | grep "var1=|var2="
var1=twenty

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote