DistributedNetworks DistributedNetworks


Unix Shell Scripts   «Prev  Next»

Using Text Editor - Exercise

Practice using the vi editor

Objective:Use vi to create and edit a script file

Exercise scoring



This exercise is worth 3 points.

Background/overview

You should have an account set up on the DistributedNetworks Labs server or on a UNIX server at your site. Log in to this account so that you see a UNIX command line prompt.

Instructions

  1. Log in to your UNIX account so that you are working at a command prompt.
  2. Start vi with a filename for the script you will create. Let’s make the filename for your script in this exercise “welcome.” So, type in the following line:

% vi welcome

  1. You see a blank screen except for a tilde character on each line. This character indicates a line beyond the end of the file (hence, the file is empty if you see only tildes). When you start vi, you always begin in command mode.
  2. Press i to change to Insert mode. The word INSERT appears at the bottom of your screen.
  3. Enter the first line of your script and press Enter. The first line of your script should be:

#!/bin/sh

  1. Press Esc to return to command mode. The word INSERT disappears.
  2. Press colon, w, q, Enter to save your file and exit from vi.
  3. View the contents of the file you just created by typing the following line:

% cat welcome

Hints

You must start vi from a directory where you have permission to create new files, such as your home directory. Ask your system administrator for assistance if you cannot create a new file in your home directory. If you are using the DistributedNetworks UNIX lab, you can create files in the directory that you begin working in (your home directory).