Unix Shell Scripts   «Prev  Next»

Using Text Editor - Exercise

Practice using the vi Editor

Objective: Use vi to create and edit a simple shell script file.

Exercise Scoring

This exercise is worth 3 points.

Background

You should have an account on the DispersedNet Labs server or on a Unix/Linux system at your site. Log in so you have access to a command-line prompt.

Instructions

  1. Log in to your Unix account and confirm you are at a shell prompt in a directory where you can create files (your home directory is usually safe).
  2. Start vi and create a new file named welcome:
% vi welcome
  1. You will see a mostly blank screen with ~ characters on many lines. These tildes indicate lines beyond the end of the file (the file is currently empty).
  2. When vi starts, it begins in command mode. Press i to enter insert mode. You should see INSERT appear at the bottom of the screen.
  3. Type the first line of the script exactly as shown below, then press Enter:
#!/bin/sh
  1. Press Esc to return to command mode (the INSERT indicator should disappear).
  2. Save the file and exit vi by typing :wq and pressing Enter.
  3. Verify the file contents from the command line:
% cat welcome

In the textbox below, paste the output you see from cat welcome. Your output should include the shebang line you entered.


Hints

  • If you cannot create files, make sure you are in a directory where you have write permission (your home directory is usually correct).
  • If you are using the DispersedNet Unix lab environment, you can create files in the default directory you start in.
  • If vi feels “stuck,” press Esc to return to command mode.