Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

So, I was playing some Zork 1 and I went to copy some text to show a friend of mine, but I accidentally forgot to hold the shift key when pressing CTRL+C. This stopped the command and I lost my Zork data...

Is there some sort of "helpful" tip out their that I can use to prevent stopping the command when press the keys CTRL+C?

Note that I'm running the game Zork via Frotz on the Terminal (emulator), I installed it from the steps given on this website here

share|improve this question
    
Is zork1 a command-line game or a graphical one? How do you start it? –  i08in Jun 6 at 2:53
    
I did the apt-get install frotz for the game engine, then I downloaded zork1 from here, then I just opened the DATA/ZORK.DAT with frotz path/to/DATA/ZORK.DAT –  Xero Jun 6 at 2:56
    
He is asking whether it is run in a terminal (emulator), or in a GUI environment, because the answer is different depending how it is run. –  No Time Jun 6 at 2:58
    
Ohhh, okay, I'll edit my answer –  Xero Jun 6 at 2:59
    
So you want Ctrl + c to prevent terminatting all applications altogether? That might be disastrous in future though. –  i08in Jun 6 at 3:00

2 Answers 2

up vote 26 down vote accepted

The key combination Ctrl+C sends the character ^C (byte value 3). This causes the terminal to send the SIGINT signal to the program running in the foreground¹. The conventional action for this signal is to interrupt the current command: programs designed to process successive commands go back to their toplevel prompt, while programs designed as a single batch command or a continuous interaction exit. Evidently the program you're using was designed according to the second model.

This signal-sending key is a feature of the general terminal interface in the kernel, shared by all terminal emulators and real physical terminals. You can configure which key sends this signal, as well as other keys (most notably CtrlZ sending SIGSTOP to suspend the foreground program) with the stty command. To switch the key for SIGINT to Ctrl+_ (in the current terminal):

stty intr '^_'

To disable it altogether:

stty -intr ''

To reset all settings to the default:

stty sane

The key cannot be an arbitrary key combination, it has to be a single byte value. The stty setting can be overridden by programs — some programs (especially full-screen text mode programs) do their own keyboard shortcut processing.

¹ More precisely, to all the processes in the foreground process group for which the terminal is the controlling terminal.

share|improve this answer
    
Very good answer, helpful, but I've already accepted an answer. This answer does go in a lot of detail though, good job. –  Xero Jun 6 at 21:59
    
@Xero The "accepted answer" can be reassigned at any time, as many times as you like. However, whether you wish to do so, is up to you. –  Chris Jester-Young Jun 6 at 22:52
    
@ChrisJester-Young Okay, I supposed I'll do that. –  Xero Jun 6 at 22:58

CTRL + C sends an interrupt signal (SIGINT, which is signal number 2) to the job in the foreground. You can disable this by "trapping" the signal using the trap '' 2 command before starting Zork.

Re-enable CTRL + C (untrap SIGINT) with trap 2.

Tip: you could add something like this to your ~/.bashrc:

alias zork="(trap '' 2 && cd ~/path/to/zork/ && frotz ZORK1.DAT)"

This way you will never forget to disable and re-enable the signal and it's easier to start the game by just typing zork in the terminal.

Note: you can use the signal name instead of the number if it's more convenient for you, i.e. trap '' sigint or trap '' int. I'm just used to using the numbers, e.g. in kill -9 and such.

share|improve this answer
    
Thanks, works perfectly, just how I wanted. –  Xero Jun 6 at 3:01
    
Even better edit, thank you. –  Xero Jun 6 at 3:15
6  
Using && does not seem appropriate here, the game could end due to some other signal and the trap would not be restored. Running the trap in a subshell might be better. –  Darkhogg Jun 6 at 20:06
    
@Darkhogg Edited my answer to invoke a subshell instead of && and pushd + popd, thanks for the tip. If you have any more suggestions, please feel free to tell me. –  kraxor Jun 22 at 11:32

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.