Coder's Guild Mailing List

Re: UNIX SCRIPT

Posted by Weasel on 1999-03-26

> When  user presses CTRL-C , I want to ask for user confirmation. If 'y'
> exit , else continue with installation.

I managed to get an if to work (Wow, my first real shell script!). I
used the bash since I do not have the k-shell installed on my system but
it might work very similar if not identical with the ksh.

I used the <test> command to check whether the value read from STDIN is
the same as "y" and if yes, echoed Exiting, released the trap and
exited.

However I did not manage to continue with the command that was
interrupted. My script continues at the command that follows the
interrupted one. If you ever find the solution to this one, please let
me know, I am really keen to know how this works.

So, here's the code:


#!/bin/bash
trap 'echo ;\
      echo Please confirm [y/n];\
      read;\
      \
      if (test $REPLY == "y") then\
          echo Exiting!!!!;\
          trap 2;\
          exit;\
      fi;\
      \
      echo Ok, I will continue;\
      \
      '\
      2
# The rest of the code
 
# just to have some time to press Ctrl C
ls -aR /
 
 
 
echo Hello
 
 
 
trap 2
# release the trap
 
echo Hi there
~

HTH

-- 
Weasel                          mailto:palfrader@xxxxxxx.xxx
Peter                   http://www.cosy.sbg.ac.at/~ppalfrad/
------------------------------------------------------------
     We have full klingon console support just in case.
                         -- Alan Cox on linux-kernel