Linux HW
|
[Spring 2018] |
IFT 250: Shell & Script Programming with Unix |
|
Lab Activity 3A: Shell, Environment, Simple Filters |
Learnings
· The difference between shell and environment variables
· How shell variables interact and are used
· Advanced formatting techniques
Part I: Variable in the Shell
Give the one-line command that makes use of semicolons and redirection to complete the following tasks on bash:
1. Create a shell variable named var1 and initialize it to “twenty”:
2. Create a shell variable named var2 and initialize it to 21:
3. Create a shell variable named var3 and initialize it to “temp”:
4. Display the values of all three variables:
5. Display the list of local shell variables and determine if var1, var2, or var3 is in the listing:
6. Display the list of environmental variables and determine if var1, var2, or var3 is in the listing:
7. Use the export command to make var1 and var3 environmental variables:
8. Display the list of environmental variables and determine if either var1 or var3 is in the listing:
9. Remove the var3 variable with the unset command:
10. Display the list of local shell variables and determine if var1, var2, or var3 is in the listing:
11. Display the list of environmental variables and determine if var1, var2, or var3 is in the listing:
12. Start a new child shell:
13. In the new child shell, display the list of local shell variables and determine if either var1 or var2 is in the listing:
14. In the new child shell, display the list of environmental variables and determine if either var1 or var2 is in the listing:
Part II: Shell game
Execute the following commands in sequential order and give the output as it appears. Be sure to write “nothing” if the only thing that appears on the screen is the next prompt and write “blank line” if a blank line is printed before the prompt.
1) bash$ i=class; j=is; k=over
2) bash$ echo $i $j $k
3) bash$ sh
4) bash$ sh$ echo $i $j $k
5) bash$ sh$ i=Be; j=nice
6) bash$ sh$ exit
7) bash$ echo $i $j $k
8) bash$ sh
9) bash$ sh$ echo $i $j $k
10) bash$ sh$ export i j
11) bash$ sh$ i=enjoy; j=this
12) bash$ sh$ echo $i $j $k
13) bash$ sh$ exit
14) bash$ echo $i $j $k
15) bash$ export i j k
16) bash$ sh
17) bash$ sh$ echo $i $j $k
18) bash$ sh$ export i j
19) bash$ sh$ i=enjoy; j=this
20) bash$ sh$ sh
21) bash$ sh$ sh$ echo $i $j $k
22) bash$ sh$ sh$ exit
23) bash$ sh$ exit
24) bash$ echo $i $j $k
Part III: Process Data 2
F gge0001x gge0001y gge0001z
D 12-30-2006 12-30-2006 12-30-2006
T 14:15:20 14:15:55 14:16:27
S a69 a69 a69
B 15.8 16.1 15
M gge06001 gge06001 gge06001
P 30.1 29.6 29.9
Q 20.2 22.3 23.4
R 1006.2 1003.5 999.8
U 1011.8 1011.8 1005
X 34.7 35.2 35.1
A 38.994 38.994 38.994
G 107.71 107.71 107.71
H 8.395 8.406 8.368
O 37.141 36.823 36.621
C 7.55 7.532 7.437
K 28.193 27.902 27.856
W 212.86 210.15 207.15
L 68.3 67.9 67.6
You will use vi only to create a file called lab3A.1.sbs that explains the steps that you followed to create the processed file including all commands and pipelines.
Part IV: Advanced Formatting and Processing
Consider the following file named addressbook:
[email protected] Li,Yi-Huey
[email protected] Solis,Erica
[email protected] Ismail,Eiko
[email protected] Rangel,Juvenal
[email protected] Vo-le,Trang
[email protected] Wang,Meiping
[email protected] Xiao,JunHui
[email protected] Chen,Lihua
[email protected] Luo,Yan
[email protected] Raghuram,Edupuganti
[email protected] Natkin,William
[email protected] Armstrong,Craig
[email protected] Ram,PrasadVanam
[email protected] Kambam,SuneethaR
[email protected] Crawford,Chris
[email protected] Robinson,Lisa
[email protected] Adi,SrikanthReddy
[email protected] Fletcher,Derrick
[email protected] Hanchate,Bhavaniprasad
[email protected] Kambhampati,RamaKrishna
[email protected] Kanumuri,RangaRaju
[email protected] Kothamachu,Pradeep
[email protected] Kurumaddali,Venkata
[email protected] Liu,Xiaomei
[email protected] Mahakali,Radha
[email protected] Murugesan,Monikadevi
[email protected] Palleti,Venkata
[email protected] Shanmugam,Viji
[email protected] Wei,Helen
[email protected] Xiao,Li
[email protected] HanumanthaReddy,Madhu
[email protected] Chakkarabavi,Beena
[email protected] Kang,Yi
The structure of the entries is as follows:
[email protected] LastName, FirstName
You are to use the techniques learned in Unit 3 to reformat the addressbook into a file named lab3.4.prc with the following format:
LastName FirstName Username EmailAddress
In addition to this, the data must be sorted by last name and the imap number must be removed from the email addresses.
For example, the entry:
[email protected] Li,Yi-Huey
will become:
Li Yi-Huey yihuey [email protected]
You will use vi to create a file called lab3.4.sbs that explains the steps that you followed to create the file including all commands and pipelines.
Submissions
Once you’ve completed all the activities, perform the following steps for submission:
1. Ensure that all your answers are correct and complete.
2. Download the files lab3.3.sbs, lab3.3.prc, lab3.4.sbs, and lab3.4.prc from the ASU file host:
https://webapp4.asu.edu/myfiles
Page | 9