[SunHELP] Sun Script

Dale Ghent daleg at elemental.org
Wed Apr 28 14:44:01 CDT 2004


On Apr 28, 2004, at 2:49 PM, Vishal wrote:

> Hello All,
>
> I would like to have the follwing script :
>
> Write a UNIX shell script that will prompt the user with information to
> enter the
> Letter "d", "o" or "s" to execute the command as follows:
> d - to list the contents of directory in long format.
> o - <name> to check if a file <name> is in the current directory and
> displays if it is present or not
> s - <name> to make a new directory called <name> and change to a the 
> new
> directory <name>
> If an input other than "d", "o" or "s" is provided, display the 
> message "no!
> try again". Put your code in a loop, so that the shell script is 
> terminated
> by inputting the number 6.
>
> if somebody can help me to write this.

This is so simple. Specifically, you are looking for the read, case, 
while and for commands in Bourne shell (sh, bash)

Example:

#!/bin/sh

loop=1

while $loop;
do

echo -n "Enter your command or 6 to quit:"
read input

case $input in

	'd')
		dostuff

	'o')
		domorestuff

	's')
		dootherstuff

	'6')
		echo "Exiting..."
		unset $loop

	'*')
		echo "Invalid Command you jerk!"
esac

done



More information about the SunHELP mailing list