How to compare “abc” with abc in a shell script?
Clash Royale CLAN TAG#URR8PPP
up vote
-3
down vote
favorite
My code need compare "stop" with stop this is stand bash string.
pi@raspberrypi:~/Voice $ ./test.sh | more
"stop"
stop
My code:
#!/bin/bash
command=stop
while :
do
QUESTION=$(cat stt.txt) #stt,txt has command "stop"
echo $QUESTION
echo $command
if [ "$QUESTION" == "$command" ]; then
echo "You said "stop"!"
break
fi
done
I had try different command="stop
", the result is same.
I try to put command=$('stop')
, it's okay only one time, then it complains:./test.sh: line 2: stop: command not found.
I don't know why it is suddenly stop working to set stop as command, not "stop"
shell-script variable test
add a comment |
up vote
-3
down vote
favorite
My code need compare "stop" with stop this is stand bash string.
pi@raspberrypi:~/Voice $ ./test.sh | more
"stop"
stop
My code:
#!/bin/bash
command=stop
while :
do
QUESTION=$(cat stt.txt) #stt,txt has command "stop"
echo $QUESTION
echo $command
if [ "$QUESTION" == "$command" ]; then
echo "You said "stop"!"
break
fi
done
I had try different command="stop
", the result is same.
I try to put command=$('stop')
, it's okay only one time, then it complains:./test.sh: line 2: stop: command not found.
I don't know why it is suddenly stop working to set stop as command, not "stop"
shell-script variable test
"the result is same" — what is the result? You didn't actually say. What did you expect to have happen?
– Wildcard
Jun 25 '16 at 0:59
1
It doesn't answer your question, but you should definitely read: Why does my shell script choke on whitespace or other special characters?
– Wildcard
Jun 25 '16 at 1:01
The result is $QUESTIONS is "stop", $command is stop, It cannot compare with eachother
– rfid gao
Jun 25 '16 at 3:01
the string in stt,txt is "stop", this is output from other application, I cannot change it, so echo $QUESTION is "stop", any string I set in command it will out put as stop.
– rfid gao
Jun 25 '16 at 3:05
add a comment |
up vote
-3
down vote
favorite
up vote
-3
down vote
favorite
My code need compare "stop" with stop this is stand bash string.
pi@raspberrypi:~/Voice $ ./test.sh | more
"stop"
stop
My code:
#!/bin/bash
command=stop
while :
do
QUESTION=$(cat stt.txt) #stt,txt has command "stop"
echo $QUESTION
echo $command
if [ "$QUESTION" == "$command" ]; then
echo "You said "stop"!"
break
fi
done
I had try different command="stop
", the result is same.
I try to put command=$('stop')
, it's okay only one time, then it complains:./test.sh: line 2: stop: command not found.
I don't know why it is suddenly stop working to set stop as command, not "stop"
shell-script variable test
My code need compare "stop" with stop this is stand bash string.
pi@raspberrypi:~/Voice $ ./test.sh | more
"stop"
stop
My code:
#!/bin/bash
command=stop
while :
do
QUESTION=$(cat stt.txt) #stt,txt has command "stop"
echo $QUESTION
echo $command
if [ "$QUESTION" == "$command" ]; then
echo "You said "stop"!"
break
fi
done
I had try different command="stop
", the result is same.
I try to put command=$('stop')
, it's okay only one time, then it complains:./test.sh: line 2: stop: command not found.
I don't know why it is suddenly stop working to set stop as command, not "stop"
shell-script variable test
shell-script variable test
edited Nov 20 at 22:34
Rui F Ribeiro
38.2k1475125
38.2k1475125
asked Jun 25 '16 at 0:44
rfid gao
191
191
"the result is same" — what is the result? You didn't actually say. What did you expect to have happen?
– Wildcard
Jun 25 '16 at 0:59
1
It doesn't answer your question, but you should definitely read: Why does my shell script choke on whitespace or other special characters?
– Wildcard
Jun 25 '16 at 1:01
The result is $QUESTIONS is "stop", $command is stop, It cannot compare with eachother
– rfid gao
Jun 25 '16 at 3:01
the string in stt,txt is "stop", this is output from other application, I cannot change it, so echo $QUESTION is "stop", any string I set in command it will out put as stop.
– rfid gao
Jun 25 '16 at 3:05
add a comment |
"the result is same" — what is the result? You didn't actually say. What did you expect to have happen?
– Wildcard
Jun 25 '16 at 0:59
1
It doesn't answer your question, but you should definitely read: Why does my shell script choke on whitespace or other special characters?
– Wildcard
Jun 25 '16 at 1:01
The result is $QUESTIONS is "stop", $command is stop, It cannot compare with eachother
– rfid gao
Jun 25 '16 at 3:01
the string in stt,txt is "stop", this is output from other application, I cannot change it, so echo $QUESTION is "stop", any string I set in command it will out put as stop.
– rfid gao
Jun 25 '16 at 3:05
"the result is same" — what is the result? You didn't actually say. What did you expect to have happen?
– Wildcard
Jun 25 '16 at 0:59
"the result is same" — what is the result? You didn't actually say. What did you expect to have happen?
– Wildcard
Jun 25 '16 at 0:59
1
1
It doesn't answer your question, but you should definitely read: Why does my shell script choke on whitespace or other special characters?
– Wildcard
Jun 25 '16 at 1:01
It doesn't answer your question, but you should definitely read: Why does my shell script choke on whitespace or other special characters?
– Wildcard
Jun 25 '16 at 1:01
The result is $QUESTIONS is "stop", $command is stop, It cannot compare with eachother
– rfid gao
Jun 25 '16 at 3:01
The result is $QUESTIONS is "stop", $command is stop, It cannot compare with eachother
– rfid gao
Jun 25 '16 at 3:01
the string in stt,txt is "stop", this is output from other application, I cannot change it, so echo $QUESTION is "stop", any string I set in command it will out put as stop.
– rfid gao
Jun 25 '16 at 3:05
the string in stt,txt is "stop", this is output from other application, I cannot change it, so echo $QUESTION is "stop", any string I set in command it will out put as stop.
– rfid gao
Jun 25 '16 at 3:05
add a comment |
3 Answers
3
active
oldest
votes
up vote
2
down vote
Thank everybody's help.
I try different one, this is working for me!
#!/bin/bash
command=""stop""
while :
do
QUESTION=$(cat stt.txt) #stt,txt has command "stop"
echo $QUESTION
echo $command
if [ "$QUESTION" = "$command" ]; then
echo "You said $command"!
break
fi
done
add a comment |
up vote
1
down vote
#!/bin/bash
command="stop"
while :
do
QUESTION=$(cat stt.txt) #stt,txt has command "stop"
echo $QUESTION
echo $command
if [ "$QUESTION" == "$command" ]; then
echo "You said $command"!
break
fi
done
I made a two changes to your script.
All strings entered directly into scripts for use in variables should be quoted, otherwise bash will try to interpret them as commands. As such this is not a valid way to declare a variable 'command' with a string value 'stop'.
command=stop
This is a valid way.
command="stop"
Also bash will try to interpret your ! as you trying to recall an event, you would need to place that outside your quotes and escape it.
echo "You said $command"!
Thank all the people's help here. I had try Zachary's code. The issue is same. $QUESTION is "stop", $command is stop, so they cannot be equal. I cannot get my result: Cpi@raspberrypi:~/Voice $ ./test.sh | more. I get "stop" stop.
– rfid gao
Jun 25 '16 at 2:57
add a comment |
up vote
1
down vote
grep -q '"stop"' < in > /dev/null && echo hooray
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Thank everybody's help.
I try different one, this is working for me!
#!/bin/bash
command=""stop""
while :
do
QUESTION=$(cat stt.txt) #stt,txt has command "stop"
echo $QUESTION
echo $command
if [ "$QUESTION" = "$command" ]; then
echo "You said $command"!
break
fi
done
add a comment |
up vote
2
down vote
Thank everybody's help.
I try different one, this is working for me!
#!/bin/bash
command=""stop""
while :
do
QUESTION=$(cat stt.txt) #stt,txt has command "stop"
echo $QUESTION
echo $command
if [ "$QUESTION" = "$command" ]; then
echo "You said $command"!
break
fi
done
add a comment |
up vote
2
down vote
up vote
2
down vote
Thank everybody's help.
I try different one, this is working for me!
#!/bin/bash
command=""stop""
while :
do
QUESTION=$(cat stt.txt) #stt,txt has command "stop"
echo $QUESTION
echo $command
if [ "$QUESTION" = "$command" ]; then
echo "You said $command"!
break
fi
done
Thank everybody's help.
I try different one, this is working for me!
#!/bin/bash
command=""stop""
while :
do
QUESTION=$(cat stt.txt) #stt,txt has command "stop"
echo $QUESTION
echo $command
if [ "$QUESTION" = "$command" ]; then
echo "You said $command"!
break
fi
done
edited Jun 25 '16 at 3:35
Mongrel
2,04131345
2,04131345
answered Jun 25 '16 at 3:18
rfid gao
191
191
add a comment |
add a comment |
up vote
1
down vote
#!/bin/bash
command="stop"
while :
do
QUESTION=$(cat stt.txt) #stt,txt has command "stop"
echo $QUESTION
echo $command
if [ "$QUESTION" == "$command" ]; then
echo "You said $command"!
break
fi
done
I made a two changes to your script.
All strings entered directly into scripts for use in variables should be quoted, otherwise bash will try to interpret them as commands. As such this is not a valid way to declare a variable 'command' with a string value 'stop'.
command=stop
This is a valid way.
command="stop"
Also bash will try to interpret your ! as you trying to recall an event, you would need to place that outside your quotes and escape it.
echo "You said $command"!
Thank all the people's help here. I had try Zachary's code. The issue is same. $QUESTION is "stop", $command is stop, so they cannot be equal. I cannot get my result: Cpi@raspberrypi:~/Voice $ ./test.sh | more. I get "stop" stop.
– rfid gao
Jun 25 '16 at 2:57
add a comment |
up vote
1
down vote
#!/bin/bash
command="stop"
while :
do
QUESTION=$(cat stt.txt) #stt,txt has command "stop"
echo $QUESTION
echo $command
if [ "$QUESTION" == "$command" ]; then
echo "You said $command"!
break
fi
done
I made a two changes to your script.
All strings entered directly into scripts for use in variables should be quoted, otherwise bash will try to interpret them as commands. As such this is not a valid way to declare a variable 'command' with a string value 'stop'.
command=stop
This is a valid way.
command="stop"
Also bash will try to interpret your ! as you trying to recall an event, you would need to place that outside your quotes and escape it.
echo "You said $command"!
Thank all the people's help here. I had try Zachary's code. The issue is same. $QUESTION is "stop", $command is stop, so they cannot be equal. I cannot get my result: Cpi@raspberrypi:~/Voice $ ./test.sh | more. I get "stop" stop.
– rfid gao
Jun 25 '16 at 2:57
add a comment |
up vote
1
down vote
up vote
1
down vote
#!/bin/bash
command="stop"
while :
do
QUESTION=$(cat stt.txt) #stt,txt has command "stop"
echo $QUESTION
echo $command
if [ "$QUESTION" == "$command" ]; then
echo "You said $command"!
break
fi
done
I made a two changes to your script.
All strings entered directly into scripts for use in variables should be quoted, otherwise bash will try to interpret them as commands. As such this is not a valid way to declare a variable 'command' with a string value 'stop'.
command=stop
This is a valid way.
command="stop"
Also bash will try to interpret your ! as you trying to recall an event, you would need to place that outside your quotes and escape it.
echo "You said $command"!
#!/bin/bash
command="stop"
while :
do
QUESTION=$(cat stt.txt) #stt,txt has command "stop"
echo $QUESTION
echo $command
if [ "$QUESTION" == "$command" ]; then
echo "You said $command"!
break
fi
done
I made a two changes to your script.
All strings entered directly into scripts for use in variables should be quoted, otherwise bash will try to interpret them as commands. As such this is not a valid way to declare a variable 'command' with a string value 'stop'.
command=stop
This is a valid way.
command="stop"
Also bash will try to interpret your ! as you trying to recall an event, you would need to place that outside your quotes and escape it.
echo "You said $command"!
answered Jun 25 '16 at 2:42
Zachary Brady
3,386831
3,386831
Thank all the people's help here. I had try Zachary's code. The issue is same. $QUESTION is "stop", $command is stop, so they cannot be equal. I cannot get my result: Cpi@raspberrypi:~/Voice $ ./test.sh | more. I get "stop" stop.
– rfid gao
Jun 25 '16 at 2:57
add a comment |
Thank all the people's help here. I had try Zachary's code. The issue is same. $QUESTION is "stop", $command is stop, so they cannot be equal. I cannot get my result: Cpi@raspberrypi:~/Voice $ ./test.sh | more. I get "stop" stop.
– rfid gao
Jun 25 '16 at 2:57
Thank all the people's help here. I had try Zachary's code. The issue is same. $QUESTION is "stop", $command is stop, so they cannot be equal. I cannot get my result: Cpi@raspberrypi:~/Voice $ ./test.sh | more. I get "stop" stop.
– rfid gao
Jun 25 '16 at 2:57
Thank all the people's help here. I had try Zachary's code. The issue is same. $QUESTION is "stop", $command is stop, so they cannot be equal. I cannot get my result: Cpi@raspberrypi:~/Voice $ ./test.sh | more. I get "stop" stop.
– rfid gao
Jun 25 '16 at 2:57
add a comment |
up vote
1
down vote
grep -q '"stop"' < in > /dev/null && echo hooray
add a comment |
up vote
1
down vote
grep -q '"stop"' < in > /dev/null && echo hooray
add a comment |
up vote
1
down vote
up vote
1
down vote
grep -q '"stop"' < in > /dev/null && echo hooray
grep -q '"stop"' < in > /dev/null && echo hooray
edited Sep 21 '16 at 12:00
Anthon
59.8k17102163
59.8k17102163
answered Sep 21 '16 at 11:15
mikeserv
45k566152
45k566152
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f291990%2fhow-to-compare-abc-with-abc-in-a-shell-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
"the result is same" — what is the result? You didn't actually say. What did you expect to have happen?
– Wildcard
Jun 25 '16 at 0:59
1
It doesn't answer your question, but you should definitely read: Why does my shell script choke on whitespace or other special characters?
– Wildcard
Jun 25 '16 at 1:01
The result is $QUESTIONS is "stop", $command is stop, It cannot compare with eachother
– rfid gao
Jun 25 '16 at 3:01
the string in stt,txt is "stop", this is output from other application, I cannot change it, so echo $QUESTION is "stop", any string I set in command it will out put as stop.
– rfid gao
Jun 25 '16 at 3:05