> Am 06.03.2017 um 15:09 schrieb Rob la Lau <r...@ohreally.nl>: > > 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 > > $ [ "x" -eq "x" ] && echo "yes" || echo "no" > [: invalid integer 'x' > no > > I hope this won't be fixed, as I rely quite heavily on this behaviour, > lacking some other short 'is integer' test.
What about these: if ! expr "$x" : '[[:digit:]]*$' >/dev/null; then echo no; fi if [ -n "${x//[0-9]/}" ]; then echo no; fi -- Reuti > > Cheers, > Rob > > -- > -- Rob la Lau > -- > -- Sysadmin en webdeveloper in ruste > -- > -- web : https://ohreally.nl/ > -- eml : r...@ohreally.nl > -- >
signature.asc
Description: Message signed with OpenPGP using GPGMail