Writing scripts to process data and automate system administration tasks is an incredibly powerful skill to develop. Developing those skills does not happen overnight or even in one class. This lab will get you started with two important tools: Shell scripting and the vim text editor.
After successful completion of this, you will be able to:
- Use the
vimapplication to edit text files - Write a bash script that reports information to the CLI
- Turn a text file into an executable shell script
Complete the following steps
Step 0: Get your materials ready
- You need to log in to Linux from a Mac or Windows computer.
- The website vimsheet.com (Links to an external site.) is a very useful reference tool for this exercise and for future work in vi/vim.
Step 1
The steps below are not very detailed on purpose. There’s very little you can do (if anything at all) to break the Linux server, so use the resources above and experiment and explore.
- Log in to Linux and launch Vim by typing
vi. You are now in a text editor, but start typing and see what happens. - If you get frustrated, hit
escand type:. Notice where the:appears. Then typeq!after the:(i.e.,:q!) and see what happens. - Enter vi again, and press
control-z(on Mac, you might have to pressfn-control-z.) It should look similar what happened above; i.e., you should be at the bash command prompt. - Type
fgand hitenter.
Answer question 1 below.
Step 2
Quit Vim and run this command from shell: vi hello.sh. Using vimsheet.com (Links to an external site.) if necessary, figure out how to edit the file so that it contains the following lines:
Save the file and exit Vim. Try to execute the file by running ./hello.sh – it shouldn’t work. Assuming it doesn’t, use your work in prior labs to troubleshoot why you cannot execute this script. Fix the problem so that you can execute the script by typing ./hello.sh.
Create a screenshot that shows the content of your script and the output after executing the script.
Answer the following questions
In a word document (or discussion thread, see below) answer the following questions:
- In Step 1 what is the difference between what happened in 1 & 2 versus 3 & 4?
- Try to run your script from Step 2 without
./– why doesn’t it work? Or, what does./do that makes it required? - Your shell script has the
.shfile extension – what would you have to do differently if you wanted to name ithi.shellbut you still wanted it to run as a shell script?


0 comments