what is the differences between kill -PIPE $$ VS exit 1
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
in my bash script I used the following syntax in order to exit from bash script
kill -PIPE $$
I use it because sometimes in function or in internal shell in the script the exit 1 not realty exit from bash script
so I use kill instead of exit 1
my question is
seems that
exit 1
and
kill -PIPE $$
are almost equal
dose my assumption is true ?
second - about kill -PIPE $$ ( any risks to use that syntax ? )
linux bash kill exit
add a comment |Â
up vote
1
down vote
favorite
in my bash script I used the following syntax in order to exit from bash script
kill -PIPE $$
I use it because sometimes in function or in internal shell in the script the exit 1 not realty exit from bash script
so I use kill instead of exit 1
my question is
seems that
exit 1
and
kill -PIPE $$
are almost equal
dose my assumption is true ?
second - about kill -PIPE $$ ( any risks to use that syntax ? )
linux bash kill exit
1
Related: unix.stackexchange.com/questions/48533/â¦
â Kusalananda
4 hours ago
3
Can you give an example of a script whereexit 1
doesn't exit butkill -PIPE $$
does?
â Joseph Sible
4 hours ago
example - ( exit 1 ) or in sub shell
â yael
3 hours ago
But why would you use(exit 1)
instead ofexit 1
?
â xenoid
1 hour ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
in my bash script I used the following syntax in order to exit from bash script
kill -PIPE $$
I use it because sometimes in function or in internal shell in the script the exit 1 not realty exit from bash script
so I use kill instead of exit 1
my question is
seems that
exit 1
and
kill -PIPE $$
are almost equal
dose my assumption is true ?
second - about kill -PIPE $$ ( any risks to use that syntax ? )
linux bash kill exit
in my bash script I used the following syntax in order to exit from bash script
kill -PIPE $$
I use it because sometimes in function or in internal shell in the script the exit 1 not realty exit from bash script
so I use kill instead of exit 1
my question is
seems that
exit 1
and
kill -PIPE $$
are almost equal
dose my assumption is true ?
second - about kill -PIPE $$ ( any risks to use that syntax ? )
linux bash kill exit
linux bash kill exit
asked 4 hours ago
yael
2,1091450
2,1091450
1
Related: unix.stackexchange.com/questions/48533/â¦
â Kusalananda
4 hours ago
3
Can you give an example of a script whereexit 1
doesn't exit butkill -PIPE $$
does?
â Joseph Sible
4 hours ago
example - ( exit 1 ) or in sub shell
â yael
3 hours ago
But why would you use(exit 1)
instead ofexit 1
?
â xenoid
1 hour ago
add a comment |Â
1
Related: unix.stackexchange.com/questions/48533/â¦
â Kusalananda
4 hours ago
3
Can you give an example of a script whereexit 1
doesn't exit butkill -PIPE $$
does?
â Joseph Sible
4 hours ago
example - ( exit 1 ) or in sub shell
â yael
3 hours ago
But why would you use(exit 1)
instead ofexit 1
?
â xenoid
1 hour ago
1
1
Related: unix.stackexchange.com/questions/48533/â¦
â Kusalananda
4 hours ago
Related: unix.stackexchange.com/questions/48533/â¦
â Kusalananda
4 hours ago
3
3
Can you give an example of a script where
exit 1
doesn't exit but kill -PIPE $$
does?â Joseph Sible
4 hours ago
Can you give an example of a script where
exit 1
doesn't exit but kill -PIPE $$
does?â Joseph Sible
4 hours ago
example - ( exit 1 ) or in sub shell
â yael
3 hours ago
example - ( exit 1 ) or in sub shell
â yael
3 hours ago
But why would you use
(exit 1)
instead of exit 1
?â xenoid
1 hour ago
But why would you use
(exit 1)
instead of exit 1
?â xenoid
1 hour ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
exit 1
exits the current subshell environment with exit code 1, so for instance in:
sh -c '(echo 1; exit 1; echo 2); echo 3'
That exit 1
exits the subshell running the code in side (...)
so that 2
is not output, and the parent shell process resumes echoing 3
.
kill -s PIPE "$$"
sends the SIGPIPE signal to the process that executed the shell interpreter currently interpreting the script. The SIGPIPE by default causes processes to terminate, and the fact that that process has been killed by SIGPIPE is reflected in its exit status.
So in:
sh -c '(echo 1; kill -s PIPE "$$"; echo 2); echo 3'
A SIGPIPE signal is sent by the subshell process to its parent process (the one that executed sh
). That parent process will die and not output 3
while the subshell process will carry on running in background and output 2
.
If you ran that command in the bash
or zsh
shell (and a few other Bourne-like shells), those shells will set the $?
parameter (its internal representation of the exit status of the last command) to something like 141, which is 128 + SIGPIPE (13 on most systems).
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
exit 1
exits the current subshell environment with exit code 1, so for instance in:
sh -c '(echo 1; exit 1; echo 2); echo 3'
That exit 1
exits the subshell running the code in side (...)
so that 2
is not output, and the parent shell process resumes echoing 3
.
kill -s PIPE "$$"
sends the SIGPIPE signal to the process that executed the shell interpreter currently interpreting the script. The SIGPIPE by default causes processes to terminate, and the fact that that process has been killed by SIGPIPE is reflected in its exit status.
So in:
sh -c '(echo 1; kill -s PIPE "$$"; echo 2); echo 3'
A SIGPIPE signal is sent by the subshell process to its parent process (the one that executed sh
). That parent process will die and not output 3
while the subshell process will carry on running in background and output 2
.
If you ran that command in the bash
or zsh
shell (and a few other Bourne-like shells), those shells will set the $?
parameter (its internal representation of the exit status of the last command) to something like 141, which is 128 + SIGPIPE (13 on most systems).
add a comment |Â
up vote
3
down vote
exit 1
exits the current subshell environment with exit code 1, so for instance in:
sh -c '(echo 1; exit 1; echo 2); echo 3'
That exit 1
exits the subshell running the code in side (...)
so that 2
is not output, and the parent shell process resumes echoing 3
.
kill -s PIPE "$$"
sends the SIGPIPE signal to the process that executed the shell interpreter currently interpreting the script. The SIGPIPE by default causes processes to terminate, and the fact that that process has been killed by SIGPIPE is reflected in its exit status.
So in:
sh -c '(echo 1; kill -s PIPE "$$"; echo 2); echo 3'
A SIGPIPE signal is sent by the subshell process to its parent process (the one that executed sh
). That parent process will die and not output 3
while the subshell process will carry on running in background and output 2
.
If you ran that command in the bash
or zsh
shell (and a few other Bourne-like shells), those shells will set the $?
parameter (its internal representation of the exit status of the last command) to something like 141, which is 128 + SIGPIPE (13 on most systems).
add a comment |Â
up vote
3
down vote
up vote
3
down vote
exit 1
exits the current subshell environment with exit code 1, so for instance in:
sh -c '(echo 1; exit 1; echo 2); echo 3'
That exit 1
exits the subshell running the code in side (...)
so that 2
is not output, and the parent shell process resumes echoing 3
.
kill -s PIPE "$$"
sends the SIGPIPE signal to the process that executed the shell interpreter currently interpreting the script. The SIGPIPE by default causes processes to terminate, and the fact that that process has been killed by SIGPIPE is reflected in its exit status.
So in:
sh -c '(echo 1; kill -s PIPE "$$"; echo 2); echo 3'
A SIGPIPE signal is sent by the subshell process to its parent process (the one that executed sh
). That parent process will die and not output 3
while the subshell process will carry on running in background and output 2
.
If you ran that command in the bash
or zsh
shell (and a few other Bourne-like shells), those shells will set the $?
parameter (its internal representation of the exit status of the last command) to something like 141, which is 128 + SIGPIPE (13 on most systems).
exit 1
exits the current subshell environment with exit code 1, so for instance in:
sh -c '(echo 1; exit 1; echo 2); echo 3'
That exit 1
exits the subshell running the code in side (...)
so that 2
is not output, and the parent shell process resumes echoing 3
.
kill -s PIPE "$$"
sends the SIGPIPE signal to the process that executed the shell interpreter currently interpreting the script. The SIGPIPE by default causes processes to terminate, and the fact that that process has been killed by SIGPIPE is reflected in its exit status.
So in:
sh -c '(echo 1; kill -s PIPE "$$"; echo 2); echo 3'
A SIGPIPE signal is sent by the subshell process to its parent process (the one that executed sh
). That parent process will die and not output 3
while the subshell process will carry on running in background and output 2
.
If you ran that command in the bash
or zsh
shell (and a few other Bourne-like shells), those shells will set the $?
parameter (its internal representation of the exit status of the last command) to something like 141, which is 128 + SIGPIPE (13 on most systems).
edited 34 mins ago
ilkkachu
53.1k780146
53.1k780146
answered 47 mins ago
Stéphane Chazelas
290k54541879
290k54541879
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f478281%2fwhat-is-the-differences-between-kill-pipe-vs-exit-1%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Related: unix.stackexchange.com/questions/48533/â¦
â Kusalananda
4 hours ago
3
Can you give an example of a script where
exit 1
doesn't exit butkill -PIPE $$
does?â Joseph Sible
4 hours ago
example - ( exit 1 ) or in sub shell
â yael
3 hours ago
But why would you use
(exit 1)
instead ofexit 1
?â xenoid
1 hour ago