[: =: unary operator expected [duplicate]
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
This question already has an answer here:
Why does my shell script choke on whitespace or other special characters?
4 answers
I need to write a script to test if a service inside of an Android emulator is ready for apk installation or not using this command
adb -s emulator-5554 shell pm list package | grep package:com.android.
If the command does not output any one of these substrings in the first line, then the avd is not ready for apk installation
Is the system running?
Can't find service
online
This is my script
if [ $(adb -s emulator-5554 shell pm list package | grep package:com.android. | head -n 1) = *"Is the system running?"* ] ||
[ $(adb -s emulator-5554 shell pm list package | grep package:com.android. | head -n 1) = *"Can't find service"* ] ||
[ $(adb -s emulator-5554 shell pm list package | grep package:com.android. | head -n 1) = *"online"* ] ; then
echo "could not find package service"
else
echo "found package service"
fi
but I get this error
./script.sh: line 4: [: =: unary operator expected
./script.sh: line 5: [: =: unary operator expected
./script.sh: line 6: [: =: unary operator expected
linux test command-substitution
marked as duplicate by Gilles
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 26 at 21:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
0
down vote
favorite
This question already has an answer here:
Why does my shell script choke on whitespace or other special characters?
4 answers
I need to write a script to test if a service inside of an Android emulator is ready for apk installation or not using this command
adb -s emulator-5554 shell pm list package | grep package:com.android.
If the command does not output any one of these substrings in the first line, then the avd is not ready for apk installation
Is the system running?
Can't find service
online
This is my script
if [ $(adb -s emulator-5554 shell pm list package | grep package:com.android. | head -n 1) = *"Is the system running?"* ] ||
[ $(adb -s emulator-5554 shell pm list package | grep package:com.android. | head -n 1) = *"Can't find service"* ] ||
[ $(adb -s emulator-5554 shell pm list package | grep package:com.android. | head -n 1) = *"online"* ] ; then
echo "could not find package service"
else
echo "found package service"
fi
but I get this error
./script.sh: line 4: [: =: unary operator expected
./script.sh: line 5: [: =: unary operator expected
./script.sh: line 6: [: =: unary operator expected
linux test command-substitution
marked as duplicate by Gilles
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 26 at 21:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This question already has an answer here:
Why does my shell script choke on whitespace or other special characters?
4 answers
I need to write a script to test if a service inside of an Android emulator is ready for apk installation or not using this command
adb -s emulator-5554 shell pm list package | grep package:com.android.
If the command does not output any one of these substrings in the first line, then the avd is not ready for apk installation
Is the system running?
Can't find service
online
This is my script
if [ $(adb -s emulator-5554 shell pm list package | grep package:com.android. | head -n 1) = *"Is the system running?"* ] ||
[ $(adb -s emulator-5554 shell pm list package | grep package:com.android. | head -n 1) = *"Can't find service"* ] ||
[ $(adb -s emulator-5554 shell pm list package | grep package:com.android. | head -n 1) = *"online"* ] ; then
echo "could not find package service"
else
echo "found package service"
fi
but I get this error
./script.sh: line 4: [: =: unary operator expected
./script.sh: line 5: [: =: unary operator expected
./script.sh: line 6: [: =: unary operator expected
linux test command-substitution
This question already has an answer here:
Why does my shell script choke on whitespace or other special characters?
4 answers
I need to write a script to test if a service inside of an Android emulator is ready for apk installation or not using this command
adb -s emulator-5554 shell pm list package | grep package:com.android.
If the command does not output any one of these substrings in the first line, then the avd is not ready for apk installation
Is the system running?
Can't find service
online
This is my script
if [ $(adb -s emulator-5554 shell pm list package | grep package:com.android. | head -n 1) = *"Is the system running?"* ] ||
[ $(adb -s emulator-5554 shell pm list package | grep package:com.android. | head -n 1) = *"Can't find service"* ] ||
[ $(adb -s emulator-5554 shell pm list package | grep package:com.android. | head -n 1) = *"online"* ] ; then
echo "could not find package service"
else
echo "found package service"
fi
but I get this error
./script.sh: line 4: [: =: unary operator expected
./script.sh: line 5: [: =: unary operator expected
./script.sh: line 6: [: =: unary operator expected
This question already has an answer here:
Why does my shell script choke on whitespace or other special characters?
4 answers
linux test command-substitution
linux test command-substitution
edited Nov 26 at 20:43
Jeff Schaller
37k1052121
37k1052121
asked Nov 26 at 20:18
the_prole
1204
1204
marked as duplicate by Gilles
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 26 at 21:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Gilles
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 26 at 21:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
In you tests, if the command substitution $(adb -s ...)
generates a multi-word string, the shell will treat it as a syntax error. You will have to quote the expansions:
[ "$(adb -s ...)" = *"Is the system running?"* ]
The result of an unquoted command substitution will undergo splitting and filename globbing just as an unquoted variable expansion does. Quoting the expansion avoids this. In your case, it's the splitting that causes issues.
With the command substitution expanded, the test may look something like
if [ word1 word2 word3 = *"some string"* ]
This is clearly a syntax error.
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
accepted
In you tests, if the command substitution $(adb -s ...)
generates a multi-word string, the shell will treat it as a syntax error. You will have to quote the expansions:
[ "$(adb -s ...)" = *"Is the system running?"* ]
The result of an unquoted command substitution will undergo splitting and filename globbing just as an unquoted variable expansion does. Quoting the expansion avoids this. In your case, it's the splitting that causes issues.
With the command substitution expanded, the test may look something like
if [ word1 word2 word3 = *"some string"* ]
This is clearly a syntax error.
add a comment |
up vote
3
down vote
accepted
In you tests, if the command substitution $(adb -s ...)
generates a multi-word string, the shell will treat it as a syntax error. You will have to quote the expansions:
[ "$(adb -s ...)" = *"Is the system running?"* ]
The result of an unquoted command substitution will undergo splitting and filename globbing just as an unquoted variable expansion does. Quoting the expansion avoids this. In your case, it's the splitting that causes issues.
With the command substitution expanded, the test may look something like
if [ word1 word2 word3 = *"some string"* ]
This is clearly a syntax error.
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
In you tests, if the command substitution $(adb -s ...)
generates a multi-word string, the shell will treat it as a syntax error. You will have to quote the expansions:
[ "$(adb -s ...)" = *"Is the system running?"* ]
The result of an unquoted command substitution will undergo splitting and filename globbing just as an unquoted variable expansion does. Quoting the expansion avoids this. In your case, it's the splitting that causes issues.
With the command substitution expanded, the test may look something like
if [ word1 word2 word3 = *"some string"* ]
This is clearly a syntax error.
In you tests, if the command substitution $(adb -s ...)
generates a multi-word string, the shell will treat it as a syntax error. You will have to quote the expansions:
[ "$(adb -s ...)" = *"Is the system running?"* ]
The result of an unquoted command substitution will undergo splitting and filename globbing just as an unquoted variable expansion does. Quoting the expansion avoids this. In your case, it's the splitting that causes issues.
With the command substitution expanded, the test may look something like
if [ word1 word2 word3 = *"some string"* ]
This is clearly a syntax error.
edited Nov 26 at 20:38
answered Nov 26 at 20:22
Kusalananda
118k16223364
118k16223364
add a comment |
add a comment |