Bash: How to escape minus in `if [ ⦠` (alias âtestâ)?
Clash Royale CLAN TAG#URR8PPP
up vote
-1
down vote
favorite
I need to test this:
kill -0 $LAST_PID;
So I wrote
if [ kill -0 $LAST_PID ] ; then ...
But this results in an error - unknown operator after -
or so.
how do I escape the options within if
?
scripting kill test
add a comment |Â
up vote
-1
down vote
favorite
I need to test this:
kill -0 $LAST_PID;
So I wrote
if [ kill -0 $LAST_PID ] ; then ...
But this results in an error - unknown operator after -
or so.
how do I escape the options within if
?
scripting kill test
1
Not sure why it's downvoted but since it is, it's probably a bad question and needs to be deleted.
â Ondra à ½ià ¾ka
Aug 15 at 23:44
add a comment |Â
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I need to test this:
kill -0 $LAST_PID;
So I wrote
if [ kill -0 $LAST_PID ] ; then ...
But this results in an error - unknown operator after -
or so.
how do I escape the options within if
?
scripting kill test
I need to test this:
kill -0 $LAST_PID;
So I wrote
if [ kill -0 $LAST_PID ] ; then ...
But this results in an error - unknown operator after -
or so.
how do I escape the options within if
?
scripting kill test
scripting kill test
edited Aug 15 at 16:27
Jeff Schaller
32.6k849110
32.6k849110
asked Aug 15 at 16:23
Ondra à ½ià ¾ka
467311
467311
1
Not sure why it's downvoted but since it is, it's probably a bad question and needs to be deleted.
â Ondra à ½ià ¾ka
Aug 15 at 23:44
add a comment |Â
1
Not sure why it's downvoted but since it is, it's probably a bad question and needs to be deleted.
â Ondra à ½ià ¾ka
Aug 15 at 23:44
1
1
Not sure why it's downvoted but since it is, it's probably a bad question and needs to be deleted.
â Ondra à ½ià ¾ka
Aug 15 at 23:44
Not sure why it's downvoted but since it is, it's probably a bad question and needs to be deleted.
â Ondra à ½ià ¾ka
Aug 15 at 23:44
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
accepted
It's not if
that you're trying to escape it from, it's test
/ [
. But you aren't testing the executing of kill
that way; you're testing strings. You want:
if kill -0 "$LAST_PID"; then ...
that will test kill
's return code.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
It's not if
that you're trying to escape it from, it's test
/ [
. But you aren't testing the executing of kill
that way; you're testing strings. You want:
if kill -0 "$LAST_PID"; then ...
that will test kill
's return code.
add a comment |Â
up vote
4
down vote
accepted
It's not if
that you're trying to escape it from, it's test
/ [
. But you aren't testing the executing of kill
that way; you're testing strings. You want:
if kill -0 "$LAST_PID"; then ...
that will test kill
's return code.
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
It's not if
that you're trying to escape it from, it's test
/ [
. But you aren't testing the executing of kill
that way; you're testing strings. You want:
if kill -0 "$LAST_PID"; then ...
that will test kill
's return code.
It's not if
that you're trying to escape it from, it's test
/ [
. But you aren't testing the executing of kill
that way; you're testing strings. You want:
if kill -0 "$LAST_PID"; then ...
that will test kill
's return code.
answered Aug 15 at 16:27
Jeff Schaller
32.6k849110
32.6k849110
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%2f462778%2fbash-how-to-escape-minus-in-if-alias-test%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
Not sure why it's downvoted but since it is, it's probably a bad question and needs to be deleted.
â Ondra à ½ià ¾ka
Aug 15 at 23:44