bash: test: no: integer expression expected [duplicate]
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
This question already has an answer here:
Bash - Integer expression expected
2 answers
I believe this line
if test "$suman_inspect" -eq "yes"; then
is causing this error (verbatim):
bash: test: no: integer expression expected
I formulated the above test
expression because I saw this example online:
if test "$#" -eq "0"; then
where this test checks to see if the length of the arguments array is 0.
So is there something wrong with both these checks? I am not sure I understand how the first could be valid but the second one invalid.
bash shell-script test
marked as duplicate by Jeff Schaller, steeldriver, Thomas Dickey, Stephen Rauch, G-Man Nov 10 '17 at 2:02
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
1
down vote
favorite
This question already has an answer here:
Bash - Integer expression expected
2 answers
I believe this line
if test "$suman_inspect" -eq "yes"; then
is causing this error (verbatim):
bash: test: no: integer expression expected
I formulated the above test
expression because I saw this example online:
if test "$#" -eq "0"; then
where this test checks to see if the length of the arguments array is 0.
So is there something wrong with both these checks? I am not sure I understand how the first could be valid but the second one invalid.
bash shell-script test
marked as duplicate by Jeff Schaller, steeldriver, Thomas Dickey, Stephen Rauch, G-Man Nov 10 '17 at 2:02
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.
Both test expressions in the question are invalid - to compare strings you need to use the==
operator, not the-eq
operator
â Alexander Mills
Nov 10 '17 at 1:04
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
This question already has an answer here:
Bash - Integer expression expected
2 answers
I believe this line
if test "$suman_inspect" -eq "yes"; then
is causing this error (verbatim):
bash: test: no: integer expression expected
I formulated the above test
expression because I saw this example online:
if test "$#" -eq "0"; then
where this test checks to see if the length of the arguments array is 0.
So is there something wrong with both these checks? I am not sure I understand how the first could be valid but the second one invalid.
bash shell-script test
This question already has an answer here:
Bash - Integer expression expected
2 answers
I believe this line
if test "$suman_inspect" -eq "yes"; then
is causing this error (verbatim):
bash: test: no: integer expression expected
I formulated the above test
expression because I saw this example online:
if test "$#" -eq "0"; then
where this test checks to see if the length of the arguments array is 0.
So is there something wrong with both these checks? I am not sure I understand how the first could be valid but the second one invalid.
This question already has an answer here:
Bash - Integer expression expected
2 answers
bash shell-script test
edited Nov 10 '17 at 0:55
asked Nov 10 '17 at 0:44
Alexander Mills
1,9441029
1,9441029
marked as duplicate by Jeff Schaller, steeldriver, Thomas Dickey, Stephen Rauch, G-Man Nov 10 '17 at 2:02
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 Jeff Schaller, steeldriver, Thomas Dickey, Stephen Rauch, G-Man Nov 10 '17 at 2:02
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.
Both test expressions in the question are invalid - to compare strings you need to use the==
operator, not the-eq
operator
â Alexander Mills
Nov 10 '17 at 1:04
add a comment |Â
Both test expressions in the question are invalid - to compare strings you need to use the==
operator, not the-eq
operator
â Alexander Mills
Nov 10 '17 at 1:04
Both test expressions in the question are invalid - to compare strings you need to use the
==
operator, not the -eq
operatorâ Alexander Mills
Nov 10 '17 at 1:04
Both test expressions in the question are invalid - to compare strings you need to use the
==
operator, not the -eq
operatorâ Alexander Mills
Nov 10 '17 at 1:04
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
Note that -eq
is for integer comparisons. For string comparisons, use ==
(or =
). Thus, you should use the following:
if test "$suman_inspect" == "yes"; then
# do something
fi
The same distinction applies for inequality operators (-gt
, -lt
, -ge
, -le
, and -ne
being used for numerical comparisons, and >
, <
, >=
, <=
, and !=
being used for string comparisons).
Note that you can also use [ expression ]
in place of test expression
; the two are synonymous.
yeah it's a shame the-eq
operator cannot compare two strings, as long as both arguments are already strings, oh well.
â Alexander Mills
Nov 10 '17 at 0:54
@Alexander Mills: I have long thought thateq
, being a string, should be used for string comparisons, while=
, being a mathematical symbol, should be used for numerical comparisons, but alas it's not the case.
â user001
Nov 10 '17 at 0:57
no language is perfect lol
â Alexander Mills
Nov 10 '17 at 1:03
@AlexanderMills String and integer comparisons are different, so it's important to have different symbols for them. For instance,[ 05 -eq 5 ]
is true, but[ 05 = 5 ]
is not -- they're different strings that represent the same integer. Also,[ 5 -lt 11 ]
is true, but[ 5 '<' 11 ]
is not, because 5 is less than 11 numerically, but comes after it "alphabetically" (i.e. in sorting order). BTW,=
is preferred over==
withtest
and[ ]
, for compatibility reasons.
â Gordon Davisson
Nov 10 '17 at 3:06
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
Note that -eq
is for integer comparisons. For string comparisons, use ==
(or =
). Thus, you should use the following:
if test "$suman_inspect" == "yes"; then
# do something
fi
The same distinction applies for inequality operators (-gt
, -lt
, -ge
, -le
, and -ne
being used for numerical comparisons, and >
, <
, >=
, <=
, and !=
being used for string comparisons).
Note that you can also use [ expression ]
in place of test expression
; the two are synonymous.
yeah it's a shame the-eq
operator cannot compare two strings, as long as both arguments are already strings, oh well.
â Alexander Mills
Nov 10 '17 at 0:54
@Alexander Mills: I have long thought thateq
, being a string, should be used for string comparisons, while=
, being a mathematical symbol, should be used for numerical comparisons, but alas it's not the case.
â user001
Nov 10 '17 at 0:57
no language is perfect lol
â Alexander Mills
Nov 10 '17 at 1:03
@AlexanderMills String and integer comparisons are different, so it's important to have different symbols for them. For instance,[ 05 -eq 5 ]
is true, but[ 05 = 5 ]
is not -- they're different strings that represent the same integer. Also,[ 5 -lt 11 ]
is true, but[ 5 '<' 11 ]
is not, because 5 is less than 11 numerically, but comes after it "alphabetically" (i.e. in sorting order). BTW,=
is preferred over==
withtest
and[ ]
, for compatibility reasons.
â Gordon Davisson
Nov 10 '17 at 3:06
add a comment |Â
up vote
3
down vote
accepted
Note that -eq
is for integer comparisons. For string comparisons, use ==
(or =
). Thus, you should use the following:
if test "$suman_inspect" == "yes"; then
# do something
fi
The same distinction applies for inequality operators (-gt
, -lt
, -ge
, -le
, and -ne
being used for numerical comparisons, and >
, <
, >=
, <=
, and !=
being used for string comparisons).
Note that you can also use [ expression ]
in place of test expression
; the two are synonymous.
yeah it's a shame the-eq
operator cannot compare two strings, as long as both arguments are already strings, oh well.
â Alexander Mills
Nov 10 '17 at 0:54
@Alexander Mills: I have long thought thateq
, being a string, should be used for string comparisons, while=
, being a mathematical symbol, should be used for numerical comparisons, but alas it's not the case.
â user001
Nov 10 '17 at 0:57
no language is perfect lol
â Alexander Mills
Nov 10 '17 at 1:03
@AlexanderMills String and integer comparisons are different, so it's important to have different symbols for them. For instance,[ 05 -eq 5 ]
is true, but[ 05 = 5 ]
is not -- they're different strings that represent the same integer. Also,[ 5 -lt 11 ]
is true, but[ 5 '<' 11 ]
is not, because 5 is less than 11 numerically, but comes after it "alphabetically" (i.e. in sorting order). BTW,=
is preferred over==
withtest
and[ ]
, for compatibility reasons.
â Gordon Davisson
Nov 10 '17 at 3:06
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
Note that -eq
is for integer comparisons. For string comparisons, use ==
(or =
). Thus, you should use the following:
if test "$suman_inspect" == "yes"; then
# do something
fi
The same distinction applies for inequality operators (-gt
, -lt
, -ge
, -le
, and -ne
being used for numerical comparisons, and >
, <
, >=
, <=
, and !=
being used for string comparisons).
Note that you can also use [ expression ]
in place of test expression
; the two are synonymous.
Note that -eq
is for integer comparisons. For string comparisons, use ==
(or =
). Thus, you should use the following:
if test "$suman_inspect" == "yes"; then
# do something
fi
The same distinction applies for inequality operators (-gt
, -lt
, -ge
, -le
, and -ne
being used for numerical comparisons, and >
, <
, >=
, <=
, and !=
being used for string comparisons).
Note that you can also use [ expression ]
in place of test expression
; the two are synonymous.
edited Nov 10 '17 at 1:04
answered Nov 10 '17 at 0:52
user001
1,47231936
1,47231936
yeah it's a shame the-eq
operator cannot compare two strings, as long as both arguments are already strings, oh well.
â Alexander Mills
Nov 10 '17 at 0:54
@Alexander Mills: I have long thought thateq
, being a string, should be used for string comparisons, while=
, being a mathematical symbol, should be used for numerical comparisons, but alas it's not the case.
â user001
Nov 10 '17 at 0:57
no language is perfect lol
â Alexander Mills
Nov 10 '17 at 1:03
@AlexanderMills String and integer comparisons are different, so it's important to have different symbols for them. For instance,[ 05 -eq 5 ]
is true, but[ 05 = 5 ]
is not -- they're different strings that represent the same integer. Also,[ 5 -lt 11 ]
is true, but[ 5 '<' 11 ]
is not, because 5 is less than 11 numerically, but comes after it "alphabetically" (i.e. in sorting order). BTW,=
is preferred over==
withtest
and[ ]
, for compatibility reasons.
â Gordon Davisson
Nov 10 '17 at 3:06
add a comment |Â
yeah it's a shame the-eq
operator cannot compare two strings, as long as both arguments are already strings, oh well.
â Alexander Mills
Nov 10 '17 at 0:54
@Alexander Mills: I have long thought thateq
, being a string, should be used for string comparisons, while=
, being a mathematical symbol, should be used for numerical comparisons, but alas it's not the case.
â user001
Nov 10 '17 at 0:57
no language is perfect lol
â Alexander Mills
Nov 10 '17 at 1:03
@AlexanderMills String and integer comparisons are different, so it's important to have different symbols for them. For instance,[ 05 -eq 5 ]
is true, but[ 05 = 5 ]
is not -- they're different strings that represent the same integer. Also,[ 5 -lt 11 ]
is true, but[ 5 '<' 11 ]
is not, because 5 is less than 11 numerically, but comes after it "alphabetically" (i.e. in sorting order). BTW,=
is preferred over==
withtest
and[ ]
, for compatibility reasons.
â Gordon Davisson
Nov 10 '17 at 3:06
yeah it's a shame the
-eq
operator cannot compare two strings, as long as both arguments are already strings, oh well.â Alexander Mills
Nov 10 '17 at 0:54
yeah it's a shame the
-eq
operator cannot compare two strings, as long as both arguments are already strings, oh well.â Alexander Mills
Nov 10 '17 at 0:54
@Alexander Mills: I have long thought that
eq
, being a string, should be used for string comparisons, while =
, being a mathematical symbol, should be used for numerical comparisons, but alas it's not the case.â user001
Nov 10 '17 at 0:57
@Alexander Mills: I have long thought that
eq
, being a string, should be used for string comparisons, while =
, being a mathematical symbol, should be used for numerical comparisons, but alas it's not the case.â user001
Nov 10 '17 at 0:57
no language is perfect lol
â Alexander Mills
Nov 10 '17 at 1:03
no language is perfect lol
â Alexander Mills
Nov 10 '17 at 1:03
@AlexanderMills String and integer comparisons are different, so it's important to have different symbols for them. For instance,
[ 05 -eq 5 ]
is true, but [ 05 = 5 ]
is not -- they're different strings that represent the same integer. Also, [ 5 -lt 11 ]
is true, but [ 5 '<' 11 ]
is not, because 5 is less than 11 numerically, but comes after it "alphabetically" (i.e. in sorting order). BTW, =
is preferred over ==
with test
and [ ]
, for compatibility reasons.â Gordon Davisson
Nov 10 '17 at 3:06
@AlexanderMills String and integer comparisons are different, so it's important to have different symbols for them. For instance,
[ 05 -eq 5 ]
is true, but [ 05 = 5 ]
is not -- they're different strings that represent the same integer. Also, [ 5 -lt 11 ]
is true, but [ 5 '<' 11 ]
is not, because 5 is less than 11 numerically, but comes after it "alphabetically" (i.e. in sorting order). BTW, =
is preferred over ==
with test
and [ ]
, for compatibility reasons.â Gordon Davisson
Nov 10 '17 at 3:06
add a comment |Â
Both test expressions in the question are invalid - to compare strings you need to use the
==
operator, not the-eq
operatorâ Alexander Mills
Nov 10 '17 at 1:04