Writing a Utility Script

Hi All ,,

I have couple of shell scripts .. I am trying to build a Utility script which would call each script

example ::

1) uni.sh
2) uni2.sh
3)uni3.sh

when i run the Util script it will come as a menu ,, once i press 1 it will call the first shell script and runs it .. Once this script is complete it should comeback to the same screen .. and when the user is pressing some wrong numbers apart from 3 it should prompt Invalid ID and comes to the same screen.. can any one help me on this !!!

Thanks!

its easier.read the input number from screen and
just use if-elsif-else control or simple if - if -if control.

Yes.. i need to do it using case command .

can anyone provide me a sample code to fix this !!

Thanks

Which part do you have a problem with? Just use an endless loop which prints the menu, reads input, and acts on it.

The following script is an bash example of select and case statements that can help you :

PS3='Choice ? '
COLUMNS=0

select choice in 'Pre-processing'  \
                 'Processing'      \
                 'Post-processing' \
                 'Exit'
do
   echo

   case "$REPLY" in
   1)   echo "Start script 1 ($choice)." ;;
   2)   echo "Start script 2 ($choice)." ;;
   3)   echo "Start script 3 ($choice)." ;;
   4)   break                            ;;
   *)   echo "Invalid choice ($REPLY)."  ;;
   esac

   echo
   REPLY=
done

Output example :

$ myscript.sh
1) Pre-processing
2) Processing
3) Post-processing
4) Exit
Choice ?<return>
1) Pre-processing
2) Processing
3) Post-processing
4) Exit
Choice ? 1

Start script 1 (Pre-processing).

1) Pre-processing
2) Processing
3) Post-processing
4) Exit
Choice ? Processing

Invalid choice (Processing).

1) Pre-processing
2) Processing
3) Post-processing
4) Exit
Choice ? 7

Invalid choice (7).

1) Pre-processing
2) Processing
3) Post-processing
4) Exit
Choice ? 4

$

Jean-Pierre.

I understood the Flow .. Just when i need to call the shell , when we press 1

just add ../uni1.sh ?? will it work

PS3='Choice ? '
COLUMNS=0

select choice in 'Pre-processing'  \
                 'Processing'      \
                 'Post-processing' \
                 'Exit'
do
   echo

   case "$REPLY" in
   1)   echo "Start script 1 ($choice)." ;;
   2)   echo "Start script 2 ($choice)." ;;
   3)   echo "Start script 3 ($choice)." ;;
   4)   break                            ;;
   *)   echo "Invalid choice ($REPLY)."  ;;
   esac

   echo
   REPLY=
done

Did you even try it?

Add /full/path/to/uni1.sh as shown:

[...]
case "$REPLY" in
1) echo "Start script 1 ($choice)." ; /full/path/to/uni1.sh;
[...]

That will echo out your chice to the command line and thenm call your uni1.sh script. It is good practice to add your full path in case the outer script is called from a different location.

call()
{
	echo "Input script name:"
	read name
	flag=0
	for i in *
	do
		if [ $i = $name ]
		then
			flag=1
		fi
	done
	if [ $flag -ge 1 ]
	then
	{
		sh $name
		exit
	}
	else
	{
		echo "Wrong file name:"
		call
	}
	fi
}
call

I Tried to run as per your instruction but gave errors

syntax error at line 14 : `)' unexpected

Add /full/path/to/uni1.sh as shown:

[...]
case "$REPLY" in
1) echo "Start script 1 ($choice)." ; /full/path/to/uni1.sh;
[...]

That will echo out your chice to the command line and thenm call your uni1.sh script. It is good practice to add your full path in case the outer script is called from a different location.
[/quote]

[...]
case "$REPLY" in
1) echo "Start script 1 ($choice)." ; /full/path/to/uni1.sh;;
2) echo ....
[...]

Jean-Pierre.

Good catch, thanks.