How to remove ^c mark from own shell? - linux

In normal terminal, If we run command like 'top' and when we pass interrupt signal through ctrl+c, command terminates But in my own shell it also terminate but also print ^c in the terminal. How can I prevent to print ^c. I need system call to do this.

This should do it:
stty -echoctl
Edit (after OP specified that a system call is needed): See man tcsetattr and the non-POSIX ECHOCTL terminal attribute.

Related

How to inject EOF for stdin on Git bash on windows 10?

I have tried the following keys: Ctrl+D, Ctrl+C, and Ctrl+Z. The programming I am running on bash doesn't stop unless EOF is reached.
Following worked for me:
Ctrl+Z, and then press Enter.
There is not exactly an EOF character, only a control character simulating "exit". And the CMD around a bash does not interpret CTRL-Z correctly.
In a git bash, that would be: Alt-Space, followed by C.
Done in a bash without any program running, that would exit the console.
Try it to see if your program intercept the control character and does exit its execution. But it might close the bash Windows all together.

What if we close the terminal before finishing the command?

Let me explain better. What is gonna happen if I run a command in Linux and before it's done and you could enter another command I close the terminal. Would it still do the command or not?
Generally, you must expect that closing your terminal will hangup your command. But fear not! Linux has a solution for that too!
To ensure that your command completes, use the nohup argument first. Simply place it before whatever you are trying to do:
nohup ./some_program
nohup ./do_a_thing -frx -file input_file.txt
nohup grep "something" giant_list_of_files/* > temp_file.txt
The nohup command stands for "no hangup" and it will ensure that the command you execute continues to run, even if you close your terminal.
It depends on the process and your environment (job control shell options, VNC, etc). But typically, no. The process will get a "hangup" signal (message) from the operating system, and upon receiving that, will quit.
The nohup command, for example, arranges for processes to ignore the hangup signal from the OS. There are many ways to achieve the same result.
I would say it will abort att the status you are in just before the session close.
If you want to be sure to complete the job, you will need to use the nohup command.
http://en.wikipedia.org/wiki/Nohup
Read about nohups and daemons (-d)...
A good link is [link]What's the difference between nohup and a daemon?
Worth look at screen command, Screen command offers the ability to detach a long running process (or program, or shell-script) from a session and then attach it back at a later time.

Octave Ctrl-C Kills Edit Window

I am using Ubuntu 12.04 and Octave:
$ octave
octave:1> _
I set my editor to gedit:
octave:1> edit editor "gedit %s"
I edit a function:
octave:2> edit someFunction
gedit opens someFunction.m as expected and prompt returns while gedit still has the file open:
octave:3> _
I run some other long-running function:
octave:3> runAllTests
While runAllTests is executing I press CTRL-C to interrupt it.
The observed behavior is that runAllTests is interrupted AND gedit is killed.
The expected behavior is that runAllTests is interrupted AND gedit is NOT killed.
Does anyone know how to stop CTRL-C from killing gedit in this circumstance? Alternatively is there another way to interrupt runAllTests without killing gedit?
The setting:
edit editor "gedit %s &"
causes octave to place the editor "in the background", so CTRL-C does not effect it and has the expected behaviour.
Try:
edit mode async
which specifies asynchronous mode of execution of the edit command
The problem is CTRL+C is also a copy command. IT may need to be customized as in Octave GUI Xoctave. They claim that customization is available.
Unfortunately, putting the forked process in background with '&' is not enough when working with the command line (octave-cli).
There is a bug open on the GNU Octave development webpage about this issue.
Of course it is not only an editor problem, but any new forked process is affected. For instance
octave> system("$TERM&")
creates a terminal in a new window, which would be killed by subsequent <ctrl-c>.
I propose a shell-based workaround. This consists in adding an additional layer of "forking in background", which would protect the final terminal (or text editor or whatever) from the signals sent to octave. In brief, I launch a terminal which launches another terminal in background, from which I kill the first terminal (so that it does not bother us).
Create an executable:
term-kill.sh
-----------------------------
#!/bin/sh
$TERM&
sleep 0.01
kill $1
-----------------------------
(note the sleep commands without which the second terminal does not have time to get detached from the first before the latter gets killed). Then, the command
octave> system("$TERM -e term-kill.sh $$&")
creates a single terminal which won't get killed.
To open a text editor, simply consider the executable
term-edit-kill.sh
------------------------
#!/bin/sh
$TERM -e $EDITOR $1&
sleep 0.01
kill $2
------------------------
and change the octave edit command through
octave> EDITOR('$TERM -e term-edit-kill.sh %s $$')
N.B.: I assumed that your system knows how to find term-kill.sh and term-edit-kill.sh, and that the variables $TERM and $EDITOR exist and suit your needs. The terminal emulator must support the -e option.

How to simply ignore output from a program when called as an external one in vim?

I can dump the output content from my external command in the main window, I can disable "Press ENTER or type command to continue" and simply store it in a register.
But how do I call an external command in vim (it can be any program, apt-get, etc) and simply avoid it creating a buffer window if an output? Simply IGNORE the output from a external command I ran? I just want to call the command from vim. The command starts a simple webserver (listening on port 8080) and I have to press ctrl+c to stop it and move away from the external command buffer.
I tried silent before !cmd, it works, but I would like to stop the process my external command created right after it was started.
EDIT: I changed my mind about the simple webserver. I another situations, just doing like the suggestion accepted answer it works.
Pipe output to /dev/null:
:!cmd &> /dev/null
Use silent as you mention to get rid of the Press ENTER or type command to continue:
:silent !cmd &> /dev/null
Read this page for more on hiding this message.

Can I abort the current running bash command?

Is it possible to manually abort the currently running bash command? So, for example, I'm using 'find' but it's taking ages... how do I manually stop it?
Some things won't respond to Ctrl+C; in that case, you can also do Ctrl+Z which stops the process and then kill %1 - or even fg to go back to it. Read the section in man bash entitled "JOB CONTROL" for more information. It's very helpful. (If you're not familiar with man or the man pager, you can search using /. man bash then inside it /JOB CONTROLEnter will start searching, n will find the next match which is the right section.)
Ok, so this is the order:
1st try: Ctrl+c
2nd try: Ctrl+z
3rd: login to another console, find the process of the command within your first console that is not responding to both previously mentioned abort/sleep keystrokes with: ps aux
Then kill the process with: kill -9 <PROCESSID>
Of course there may be smarter parameters to the ps command or the possibility to grep , but this would complicate the explanation.
Press CtrlC to send SIGINT to the command to attempt to interrupt it.

Resources