I dont want to exit the program by ctrl + c


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I dont want to exit the program by ctrl + c
# 1  
Old 09-21-2012
Tools I dont want to exit the program by ctrl + c

Hey , guys I am new to shell programing ,, so need a help from you guys ...

I have to write a shell script that accepts file name or directory name from the user if it is a directory then throw an error if it is a file then give the user two options .
1.overwrite the content
2.append the content


Here is my program ..

Code:
echo " Enter the File name or Directory name"
read fname
if test -d $fname # we are checking fname is a directory or not
then # if it is a directory 
echo " Please enter a file Not a directory "
else
echo " 1. Overwrite the contents of $fname "
echo " 2. Append the contents to your $fname "
read val
case $val in
1) 
clear
echo "Write your content:"
cat > $fname
#read content
#echo $content> $fname
;; 
2) 
clear
echo "Write your content:"
cat >> $fname
#read content
#echo $content>> $fname
;;
*) # All other user input results in an usage message
    clear
    #echo Please choose alternatves 1, 2 or 3
    sleep 2
    ;;
esac
fi


My problem is that I want to throw a message after the file is overwritten or appended without exiting the program
I have tried to use ctrl+c but it takes me out of the whole program .

Do correct me if I am wrong anywhere .

Last edited by fpmurphy; 09-22-2012 at 09:13 PM..
# 2  
Old 09-21-2012
Perhaps there are better ways to solve it, but it works if you use ctrl-d instead.
Please use code-tags instead, and use indenting in your code for better readability.
This User Gave Thanks to 244an For This Post:
# 3  
Old 09-22-2012
thanks ,, buddy my problem is solved ..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script Works But Need It to Exit Upon Closing Program

Running Xubuntu 16.04 with shell version "GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)," I have a working script that consistently renames a Chrome window: #!/bin/sh while sleep 1; do xdotool search --name chrome 2>/dev/null | while read id; do xdotool set_window --name... (21 Replies)
Discussion started by: jakefish
21 Replies

2. Shell Programming and Scripting

Exit script and open program via other user

Hello all.. so i have a problem i need to solve .. #! /bin/bash $SHELL dtterm -title my_prog -e su -user -c 'export DISPLAY=:0.0 ; /path/to/my/prog' & 2> /dev/null $SHELL intr exit This script will work on solaris 10 system in right clikt menu - in a secure system so i need to... (0 Replies)
Discussion started by: defs
0 Replies

3. Shell Programming and Scripting

Automation of keyboard inputs..like Ctrl+d and Ctrl+a

Hi..! I'm stuck with my automation of starting a process and keeping it running even after the current ssh session has exited.. So i'm trying to use command 'screen'. which is doing exactly what i wanted, But the problem is automation of the same. i will have to press Ctrl+a and Ctrl+d for... (2 Replies)
Discussion started by: chandana hs
2 Replies

4. UNIX for Dummies Questions & Answers

Ctrl-V + Ctrl-J for newline character does not work inside vi editor

Hi friends, I am trying to add a newline char ('\n') between the query and the commit statement in the following shell script. #! /bin/sh echo "select * from tab; commit;" > data.sql I have tried typing in "Ctrl-V + Ctrl-J" combination which has inserted ^@ (NUL) character but the commit... (1 Reply)
Discussion started by: royalibrahim
1 Replies

5. Shell Programming and Scripting

How to handle CTRL+Z or CTRL+C in shells script?

Hi, while executing shell script, in the middle of the process, if we kill the shell script( ctrl+z or ctrl+c), script will be killed and the files which using for the script will be in the folder. How to handle those scenarios. Is there any possibilities, if user breaks the script, I need to... (3 Replies)
Discussion started by: ckchelladurai
3 Replies

6. AIX

Help with AIX XL C++ complier: app exit before main program

I have two shared libraries, A, B(B depents on A, both linked with -G option which means they're rtl enable), B's toc size is bigger than 64K(-bbigtoc), while A's toc size smaller than 64K. Then I write a "Hello, world" example E, and link with A and B. Link cmd 1: xlC128_r -o E E.o -lA -lB... (0 Replies)
Discussion started by: jackliang
0 Replies

7. Shell Programming and Scripting

Dont have a clue which program to use to process flying bat data

Hi, Im not a unix person but need to analyse some data. This is bat data (animals) from large roosts using data loggers. I think AWK is probably the best thing to use but dont really know so any help appreciated. (python, grep) whichever it is, I'll have to learn it! here is an example of... (27 Replies)
Discussion started by: cmp260
27 Replies

8. Shell Programming and Scripting

Ctrl-C or Ctrl-Z causing exit the session

H! I have written script where it need to invoke the perl script in background, then write the pid in temp file then bring back the job to foreground. whenever the Ctrl-C or Ctrl-Z is pressed in the script has to exit and prompt should be dispalyed. but this script causing exit from shell session... (2 Replies)
Discussion started by: jramesh1
2 Replies

9. UNIX for Dummies Questions & Answers

EXIT from a Program not from the function..

Hi, I want a command in unix shell script which will exit my whole program, not only from the function it's using. For e.g: $1 == "m_who" && $4 == "Extrnl Vendor" { print "You don have access" exit (0); } If this error is showing on the screen, then nothing should not... (9 Replies)
Discussion started by: ronix007
9 Replies

10. AIX

Disable ctrl-c,ctrl-d,ctrl-d in ksh script

I wrote a ksh script for Helpdesk. I need to know how to disable ctrl-c,ctrl-z,ctrl-d..... so that helpdesk would not be able to get to system prompt :confused: (6 Replies)
Discussion started by: wtofu
6 Replies
Login or Register to Ask a Question