bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -eq and strings


From: Charles Daffern
Subject: Re: -eq and strings
Date: Mon, 06 Mar 2017 15:00:28 +0000
User-agent: K-9 Mail for Android

On 6 March 2017 14:09:39 GMT+00:00, Rob la Lau <address@hidden> wrote:
>On 06-03-17 14:18, Greg Wooledge wrote:
>> You're misunderstanding.  In a math context, which you are creating
>here
>> by using -eq, the word 'x' is interpreted as a variable name, which
>may
>> contain another variable name, and so on, until finally an integer is
>> discovered.
>
>Thanks. Now that I know it, I can indeed find it in the docs.
>
>I guess this means that actually test and [ are 'broken':
>
>$ test "x" -eq "x" && echo "yes" || echo "no"
>test: invalid integer 'x'
>no

It is my understanding that [ is a standard command mandated by POSIX which may 
be implemented as an external command. It would be unreasonable to expect an 
external command to be able to introspect shell variables, and similarly I 
would be surprised to find a shell which does this substitution in the [ 
command. For that reason it would certainly break my usual expectations for how 
my scripts should run, and it might possibly become a source of bugs. In the 
case of [[ however, it is entirely understandable because it is expected that 
the shell does magic in that case (new parsing rules etc.).
-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]