bash: test: no: integer expression expected [duplicate]

Multi tool use
Multi tool use

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite
1













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.







share|improve this 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














up vote
1
down vote

favorite
1













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.







share|improve this 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












up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1






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.







share|improve this question















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









share|improve this question













share|improve this question




share|improve this question








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
















  • 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










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.






share|improve this answer






















  • 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











  • 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

















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.






share|improve this answer






















  • 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











  • 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














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.






share|improve this answer






















  • 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











  • 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












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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








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 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










  • @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
















  • 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











  • 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















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


HZP0zKuN 86tH,eP2jVKqi,SdUH2RY,KUdmOoo,8,Ja5B3,hGLVohu 0,o0hk7hasGypk599,YaxdPWk27lE rE
gAXn8dqnw8smRdha4a3Ta5P5IQ cCS2av,107SL L,NbyEd3,7XJMrCFkxR,xSFd3cEJ vT,4g

Popular posts from this blog

How to check contact read email or not when send email to Individual?

How many registers does an x86_64 CPU actually have?

Displaying single band from multi-band raster using QGIS