Coder's Guild Mailing List

UNIX SCRIPT

Posted by Dhruva on 1999-03-25

Hi,
    I have written a unix script for installing a product on UNIX
machine. I am trapping the signals to prevent incomplete installation
due to CTRL-C or KILL or TERMINATE and other interrupts. The command
'TRAP" lets me to execute unix commands when a signal is raised in the
process, but I am unable to perform a condition check like 'IF'.
Here is a sample code that works without the condition check. Can
someone help me in using an 'IF' statement in 'TRAP' command.
Ex:
When  user presses CTRL-C , I want to ask for user confirmation. If 'y'
exit , else continue with installation.
-------------------------------------------------------------------
#!/bin/ksh
trap "echo 'Please confirm [y/n]'; read ii; echo Exiting !!!!"  2
# The rest of the code
-
-
-
trap 2
# release the trap
----------------------------------------------------------------
This script prompts the user when CTRL-C is pressed for confirmation.
The problem is how do I check for the entry ie., use an 'IF' statement
after 'read ii' command ???

PS: The number 2 is signal raised when CTRL-C  is pressed.

I hope someone can help me out so that I can tidy up the code. This is
the only lacking part.

Thanks in advance,
Dhruva