How do I exit or cancel inline commands in the terminal? - mysql

If I'm in the Terminal and I want to exit or cancel a command how would I do so? Escape does nothing and hitting the up arrow copies the command.

Ctrl + C is used to kill a process with the signal SIGINT, and can be intercepted by a program so it can clean its self up before exiting, or not exit at all.
Ctrl + Z is used for suspending a process by sending it the signal SIGSTOP, which cannot be intercepted by the program.
Random fact:
If you were writing a long command such as $ cd /User/myname/Desktop -r grep | .*.* and want to delete it press Ctrl + U.

Type \c and hit return. That will clear the current input statement.

Related

How to make a github workflow error message show up in log and annotations?

I have a workflow step that runs this last stage of a shell command in a loop:
|| echo "::error Filename $filename doesn't match possible files" && exit 1 ; done
The exit is triggered appropriately, but the only annotation I see is:
Error: Process completed with exit code 1.
The log shows the entire shell command pipeline and also that same error message, but not my echo'd error.
How do I get my output, including the $filename variable, included?
You have wrong syntax:
echo "::error::Filename $filename doesn't match possible files"
You need to postfix error with ::
Here is a working example of workflow using my suggestion:
https://github.com/grzegorzkrukowski/stackoverflow_tests/actions/runs/1835152772
There must be something else wrong with your workflow if it doesn't work - other command is exiting with code 1 before it has a chance to execute.

How will I be able to senda ctrl + c in tcl

Is there a way that I could send a Ctrl+C signal a tcl program?
I am having a tcl code in which when I execute it, internally it should undergo through Ctrl+C signal and print something like:
puts "sent ctrl+c" within the same file.
proc abc {
# Want to sent ctrl + c"
Here I want the command for ctrl+c
puts " sent ctrl+c"
}
If you are sending the signal to a program under the control of Expect, you do:
send "\003"
That's literally the character that your keyboard generates immediately when you do Ctrl+C; it gets translated into a signal by the terminal driver.
Otherwise, you need to use the TclX package (or Expect, though you should only use that if you need its full capabilities) which provides a kill command:
package require Tclx
kill SIGINT $theProcessID
# You could also use INT or 15 to specify the signal to send.
# You can provide a list of PIDs instead of just one too.
Knowing what process ID to send to is a matter of keeping track of things when you create the process. The current process's PID is returned by the pid command if you don't give it any arguments. The process ID(s) of the subprocesses created are returned by exec ... & for all the (known) processes in the background pipeline it creates. For pipelines created with open |..., pass the channel handle for the pipeline to the pid command to get the subprocess IDs.
set pipeline [open |[list program1 ... | program2 ... | program3 ...] "r+"]
puts $pipeline "here is some input"
set outputLine [gets $pipeline]
kill SIGINT [pid $pipeline]
# This close *should* probably produce errors; you've killed the subprocesses after all
catch {close $pipeline}
If you're handling the interrupt signal, use the signal command from TclX to do it:
package require Tclx
signal error SIGINT; # Generate a normal Tcl error on signal
signal trap SIGINT {; # Custom signal handler
puts "SIGNALLED!"
exit
}
signal default SIGINT; # Restore default behaviour
If you use signal error SIGINT, the error generated will have this message “SIGINT signal received” and this error code “POSIX SIG SIGINT”. This is easy to test for (especially with Tcl 8.6's try … trap … command).

How to close the console in the geth console

In Ethereum I opened the javascript console with "geth console" but I can not close it anymore.
I have tried ctrl-c, but it does not work.
Just type exiton the geth console
Ctrl + c is the shortcut to clear the input prompt.Ctrl + d will exit the console when the input line is clear.
Alternatively, you can type the command exit

Is there a way to configure dbx to treat a blank command as a repeat of the last command?

In gdb, if I just hit return, it repeats the last command. Is there a way to configure Sun/Oracle/Solaris dbx to do likewise?
You can get that behavior by enabling "gdb mode" in dbx.
(dbx) gdb on
(dbx) step
stopped in main at line 4 in file "t.c"
4 printf("world");
(dbx)
step
stopped in main at line 5 in file "t.c"
5 printf("!");
(dbx)
step
stopped in main at line 6 in file "t.c"
6 printf("\n");
(dbx)
step
helloworld!
stopped in main at line 7 in file "t.c"
7 }
Here is the help for gdb mode from the latest dbx.
(dbx) help gdb
gdb (command)
gdb on | off
Use `gdb on' to enter the gdb command mode under which dbx will understand
and accept gdb commands. To exit the gdb command mode and return to the dbx
command mode, enter "gdb off". Please note that the dbx commands will not
be accepted while in gdb command mode and vice versa. All debugging settings
such as breakpoints are preserved across different command modes. The
following gdb commands are not supported in the current release:
- commands - define
- handle - hbreak
- interrupt - maintenance
- printf - rbreak
- return - signal
- tcatch - until
Looks like you can use the $repeatmode for this.
I got the following from the dbx-guide
Repeating Commands
You can execute any of the commands contained in the history list. Each
history command begins with an exclamation point (!):
!! Repeats the previous command. If the value of the dbx
variable $repeatmode is set to 1, then entering a carriage
return at an empty line is equivalent to executing !!. By
default, $repeatmode is set to 0.
There also seems to be another option 'gdb on' which makes dbx behave like gdb. I haven't tried either as I don't have access to dbx right now, so you can let me know if this works for you.

Handle exit command executed by embedded Tcl runtime

I have a small shell application that embeds Tcl to execute some set of Tcl code. The Tcl interpreter is initialized using Tcl_CreateInterp. Everything is very simple:
user types Tcl command
the command gets passed to Tcl_Eval for evaluation
repeat
But if a user types 'exit', which is a valid Tcl command, the whole thing - Tcl interpreter and my shell application - exit automatically.
Q: is there any way I can catch this exit signal coming from Tcl interpreter. I really would like not to check every user command. I tried Tcl_CreateExitHandler, but it didn't work.
Thanks so much.
Get rid of the command
rename exit ""
Or redefine it to let the user know it's disabled:
proc exit {args} { error "The exit command is not available in this context" }
Also worth considering is running the user's code in a safe interp instead of in the main shell. Doing so would allow you to control exactly what the user has access to.
You might also be able to create a child interp (non-safe) and just disable the exit command for that interp.
Lastly, you could just rename exit to something else, if you're only trying to avoid users typing it by mistake:
namespace eval ::hidden {}
rename exit ::hidden::exit
Rename the exit command:
rename exit __exit
proc exit {args} {
puts -nonewline "Do you really want to exit? (y/n) "
flush stdout
gets stdin answer
if {$answer == "y"} {
__exit [lindex $args 0]
}
}
This way, when the user type exit, he/she will execute your custom exit command, in which you can do anything you like.
Using Tcl_CreateExitHandler works fine. The problem was that I added a printf into the handler implementation and the output didn't show up on the terminal. So I thought it hasn't been called. However, by the time this handler is executed there is no stdout any more. Running strace on the application shows that the handler is being executed fine.
Another solution to this problem can be to use atexit and process the exit event there.