[go: up one dir, main page]

0% found this document useful (0 votes)
10 views4 pages

Linux Shell Script Lab

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

Linux Shell Script Lab

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

NOS 110 – OPERATING SYSTEM CONCEPTS

Linux Shell Script Lab

A reminder that the images you see in this document are for reference only. As you know, Web Sites
are frequently changing. The images in this document were accurate at the time of writing. They may
have changed since then.

Objectives
Students will be able to:

• Create and run a bash script with variables.

These instructions should all be done from a Terminal session.


Please be sure to follow the commands in this lab explicitly.

Instructions
Open a word processing document for pasting your lab answers and screen shots. Save the file as
Lastname-LinuxShellScriptLab.docx. Enter the answers for all the lab questions, and copy & paste all
screen shots with the host operating system in the background where requested in the order of the
following activities. Save your file periodically.

Linux File System Lab


1. Start your Ubuntu OS Virtual Machine, and login.

2. Open a Terminal application window.

3. Create a new directory called scripts in your home directory, and position yourself in that
directory.

4. Using vi, create a one-line script called myname that generates the following output. Note: One
(1) line of code needs to generate 3 lines of output. (HINT: Reference the section on “Escape
Sequence” in the Linux Shell Document provided with this lab.)
My name is:
Your First Name
Your Last Name
NOS 110 – OPERATING SYSTEM CONCEPTS

5. Save your change and leave vi. Without changing the permissions on the script, execute the
script. (HINT: How can you execute a script if none of the permissions are set to executable? See
the Linux Shell Document provided with this lab for help.)

6. If your output does NOT look like that shown in Step 4, correct your script (until it does).

7. Edit the myname script. Add a comment as the first line of the script documenting what the
script does then add the clear command.

8. Take a screenshot of your vi Terminal window. Type Step #8 in your document. Paste the
screenshot in your Word Document. Make sure the Terminal window is displaying the vi
session and ALL your lines of code. No example image provided.

9. Without leaving vi, and using ONLY one command line, determine how many processes you are
currently running. (HINT: How do you issue shell commands within vi? :! )

10. After looking at the output of your command and BEFORE returning to vi, take a screenshot of
your Terminal window. Type Step #10 in your document. Paste the screenshot in your Word
Document. Make sure the Terminal window is displaying the results of the command issued to
determine how many processes are currently running. No example image provided. When you
are done, press ENTER to return to vi.

11. Save your changes and leave vi. Use the chmod command to make the script executable and
execute the script by simply typing myname. (HINT: There are two things you have to do.)

12. Type Step #12 in your document. Type the command(s) you used to complete Step 11 in your
Word Document.

13. From the Shell prompt, create an alias called logout and set it equal to the command exit. (If
you already have a logout alias, choose another name like goodbye.)
Issue the logout command
Open a new Terminal window.
Issue the logout command in the new Terminal window.

14. Type Step #14 in your document. Type the answer to these two questions. (1) What happened?
(2) Why? in your Word Document.

15. Change to your home directory, make a backup copy of .bashrc and name it .bashrc_bkp.
Edit .bashrc (using vi)
Position your cursor at the very bottom of the file
At the very bottom of the file, add the logout alias to .bashrc
Add one other alias you might want, e.g. alias cls=’clear’.
NOS 110 – OPERATING SYSTEM CONCEPTS

16. Take a screenshot of your vi Terminal window. Type Step #16 in your document. Paste the
screenshot in your Word Document. Make sure the Terminal window is displaying the vi
session and the LAST PAGE of your “.bashrc” file with the above edit(s). No example image
provided.

17. Save your changes and leave vi.

18. Try issuing one of the commands you just defined as an alias. It should NOT work.

19. Without logging off the system, and without explicitly defining any of your aliases, make the
aliases you just put in .bashrc available to you. (HINT: How do you execute .bashrc without
logging off and on?)

20. Type Step #20 in your document. Type the command(s) you used to complete Step 19 in your
Word Document.

21. From the shell, issue the following command:


echo “Now is the time for all good men to come to the aid of their country”

22. Retrieve the previous command (HINT: how do you retrieve previous commands on the
command line?)

23. Change the word men to women, then reissue the command.

24. Take a screenshot of your Terminal window. Type Step #24 in your document. Paste the
screenshot in your Word Document. Make sure the Terminal window is displaying BOTH
executions of the “echo” command. (One with “men” in it and one with “women” in it.) No
example image provided.

25. Make sure you are positioned in your scripts directory. Create a file named mysection and enter
the code required to accomplish the following:
Clear the screen
Create a variable called name that contains your first and last name (HINT: You need
quotes if you are going to have a blank in your variable.)
Create a variable called class that contains the string NOS 110 (see previous HINT)
Create a variable called section that contains the string: your-class-section

26. Staying in vi, and using the variables you just defined, enter commands that will display the
following:
My name is your-first-and-last-name
This class is NOS 110
The section is your-class-section
<print a blank line>
NOS 110 – OPERATING SYSTEM CONCEPTS

27. Take a screenshot of your vi Terminal window. Type Step #27 in your document. Paste the
screenshot in your Word Document. Make sure the Terminal window is displaying the vi
session and the commands entered in Step 26. No example image provided.

28. Save your file and leave vi. Execute the script to make sure it works properly.

29. Take a screenshot of your Terminal window. Type Step #29 in your document. Paste the
screenshot in your Word Document. Make sure the Terminal window is displaying the results
of the execution of the script “mysection”. No example image provided.

30. From the scripts directory, clear the screen.

31. Issue the command that will give you a long listing of ALL the files in the directory, and redirect
the output to a file named longlist.

32. DO NOT CLEAR THE SCREEN.

33. Issue the ls command.

34. Take a screenshot of your Terminal window. Type Step #33 in your document. Paste the
screenshot in your Word Document. Make sure the Terminal window is displaying the results
of the commands issued in Step 31 & 33. No example image provided.

35. Close the Terminal window.

36. Save your Lastname-ShellScriptLab.docx file. Upload to Blackboard using the assignment link
provided in the lesson.

37. If you are done with your Ubuntu Linux labs, log out and shutdown.

You might also like