Re: -eq and strings

2017-03-06 Thread Rob la Lau
On 06-03-17 16:09, Geir Hauge wrote: > If you're counting milliseconds, pattern matching should be slightly > faster than your -eq hack. Without benchmarks, I'll take your word for this. But this really convinced me: > See also http://mywiki.wooledge.org/BashFAQ/054 "this method fails if the sh

Re: -eq and strings

2017-03-06 Thread Geir Hauge
On Mon, Mar 06, 2017 at 03:31:31PM +0100, Rob la Lau wrote: > On 06-03-17 15:16, Reuti wrote: > > if ! expr "$x" : '[[:digit:]]*$' >/dev/null; then echo no; fi > > > > if [ -n "${x//[0-9]/}" ]; then echo no; fi > > True, but regular expressions are usually considered expensive. > (Must admit I ne

Re: -eq and strings

2017-03-06 Thread Charles Daffern
On 6 March 2017 14:09:39 GMT+00:00, Rob la Lau 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

Re: -eq and strings

2017-03-06 Thread Rob la Lau
On 06-03-17 15:16, Reuti wrote: > if ! expr "$x" : '[[:digit:]]*$' >/dev/null; then echo no; fi > > if [ -n "${x//[0-9]/}" ]; then echo no; fi True, but regular expressions are usually considered expensive. (Must admit I never benchmarked.) And I know 1 regex won't considerably slow down my scri

Re: -eq and strings

2017-03-06 Thread Reuti
> Am 06.03.2017 um 15:09 schrieb Rob la Lau : > > 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 final

Re: -eq and strings

2017-03-06 Thread Rob la Lau
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

Re: -eq and strings

2017-03-06 Thread Greg Wooledge
On Sat, Mar 04, 2017 at 01:15:58PM +0100, Rob la Lau wrote: > Looking a bit further: it doesn't do any comparison on the given strings: > > $ [[ "x" -eq "y" ]] && echo "yes" || echo "no" > yes You're misunderstanding. In a math context, which you are creating here by using -eq, the word 'x' is i

Re: -eq and strings

2017-03-04 Thread Chet Ramey
On 3/4/17 7:15 AM, Rob la Lau wrote: > Hello, > > I'm not sure whether I found a bug in Bash or in it's documentation. > > The documentation suggests that the arithmetic binary operator '-eq' is > for integers ("Arg1 and arg2 may be positive or negative integers."), > but when using it with '[[ ]

-eq and strings

2017-03-04 Thread Rob la Lau
Hello, I'm not sure whether I found a bug in Bash or in it's documentation. The documentation suggests that the arithmetic binary operator '-eq' is for integers ("Arg1 and arg2 may be positive or negative integers."), but when using it with '[[ ]]' it doesn't fail on strings. $ [[ 1 -eq 1 ]] &&