Sorry, people. Now I saw that my question was a bit unclear and misleading.
Thanks for the answer, Haertig.
I wanted a key shortcut that works exactly like the ctrl-z does in your example. And in fact, ctrl-c does! LOL I even wrote a small C program to make sure the behavior with shell's commands (like sleep) wasn't different from normal programs.
But I wasn't crazy when I wrote the question, although I was distracted to one VERY important detail: it was a shell script. My need is to send a "kill the current command" for .sh scripts, but let them continue. Typing a ctrl-c with aliases and functions kills just the current one! The second question: how to fully stop a function/alias? Let it quiet for now.
So, the question is: can I kill the current command being executed inside a script? (a short and simple way, not using ps+kill bruteforce)
Some tests I used now, that anyone can repeat:
The nap.c program:
Code:
// Compile with: gcc -Wall nap.c -o nap
// Execution: ./nap [seconds = 10]
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int t=10;
if (argc>1)
t = atoi( argv[1]);
printf("Sleeping %d seconds...\n", t);
sleep(t);
printf("Woke up! [%d]\n", t);
return 0;
}
The naps.sh script:
Code:
#!/bin/bash
./nap; ./nap 2; ./nap 3; ./nap 4
Testing lines:
Code:
# ctrl-c kills a single one, you won't see "woke up" for it
./nap; ./nap 2; ./nap 3; ./nap 4
# Within an alias it also kills a single one
alias naps="./nap; ./nap 2; ./nap 3; ./nap 4"
naps # hit ctrl anytime to kill each single instance
# Within a function too
function nnnap() { ./nap; ./nap 2; ./nap 3; ./nap 4; }
nnnap # hit ctrl anytime to kill each single instance
# But within a shell script, is it possible?
./naps.sh