Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to know how we can map the keys Ctrl-D in ksh to exit the shell as it does in bash shell.

Not much familiar with key binding in ksh.

Edit

My comments are after the <!-- string below.

$ echo $0
bash
$ exit    <--- I pressed Ctrl-D here, 'exit' string was placed and the shell exited

$> echo $0
ksh
$> Use `exit' to leave ksh  <!-- I pressed Ctrl-D here, Got this message and returned to the ksh prompt
$> echo $0
ksh
$> cat >> somefile
Some text
$>   <!-- I pressed Ctrl-D here. So this key combination is taken as eof char for file, but not for exit.

So, it's needs Ctrl-D to be mapped to exit the shell? How do I do that?

share|improve this question
1  
If you enter ^D after some characters, it isn't heeded as "end of file". It must go on a line on its own. –  vonbrand Feb 8 '13 at 14:03
    
Ctrl+D should work in the same way in bash and ksh. What different behavior do you observe? –  Gilles Feb 8 '13 at 22:42
    
@vonbrand Please see my update. –  mtk Feb 12 '13 at 8:41
    
It works the same. Just that bash writes exit when exiting, ksh doesn't. –  vonbrand Feb 12 '13 at 12:00
    
@vonbrand No, it isn't exiting the ksh. That's what I showed. Please check. I am still on ksh shell. It has not exitted. –  mtk Feb 12 '13 at 12:08
add comment

1 Answer

You want the stty command: see how ^D is mapped with stty -a. You can change that to something else with stty eof char: Remove the "eof" setting with stty eof undef


Untested: you want to read about the trap command in the ksh man page. It might be sufficient for you to set up a handler for the EXIT signal.

# warning: completely untested
exit_handler() { echo "exit"; exit; }
trap exit_handler EXIT
share|improve this answer
1  
To remove a terminal binding, use ^- or undef as the key, e.g. stty eof under. This is specified in POSIX. –  Gilles Feb 8 '13 at 22:41
    
Ah, thanks Gilles. –  glenn jackman Feb 8 '13 at 23:43
    
@glenn Please see my update. –  mtk Feb 12 '13 at 8:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.