Tutorial #13 - Write and execute simple shell scripts


1.  Log on to Unix if necessary.

2. Use vi to create a file named longlist.  It should display the long

form of the current directory and pipe it to the screen with more.  If 

you like, add a short message to the file.

3. Create a script file named both that asks the user to enter the first name;

It should be entered on the next line.  Assign that value to fname.  Then 

ask for the last name entered on the same line as the message and assign

it to lname.  Display both values on the same line, then display 

"Goodbye, now" and end the script.

4. Check the contents of .profile in your home directory to see if the PATH

command includes $HOME/bin. If not, add this to the end of the PATH 

command in this file.  It won't take effect until you start your next UNIX

session.

5. Create a new directory named bin, under your home directory, and move

both scripts to it.  Then make both scripts executable.

6. Run the scripts from the bin directory.  If they don't work correctly, edit 

them until they do work the way you want.  Then try running them from other

directories.


If it doesn't work:

A. The longlist file should contain this command: ls -l | more.  A message with
echo can precede or follow it.

B.The both file should contain commands such as:
	echo "Please type your first name."
	read fname
	echo "Now type your last name.\c"
	read lname
	echo "Thank you, $fname $lname"
	echo "Goodbye, now."

C. Be sure to use chmod u+x longlist both or chmod 755 longlist both to make 
the scripts executable.

D. If your scripts won't run unless you are in the directory that contains them,
your PATH command is not working properly. Make sure that you preceded your
directory name with a colon (:) in the PATH command.  Also, try logging off and
back on again.

Questions? Robert Katz:rkatz@ned.highline.edu
Last Update November 20, 2002