[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bash-bug
Subject:    Re: ind=`expr index "${string}" is` -----bug
From:       Pierre Gaston <pierre.gaston () gmail ! com>
Date:       2018-03-18 14:02:23
Message-ID: CAPSX3sT_WypofC34fG+pUAuPWCq0ccYp_4r3NnLzB6-k6gdn+Q () mail ! gmail ! com
[Download RAW message or body]

> From: zangwenkuo
>
> To: bug-bash@gnu.org
> when i use the fun as title (expr)
> i got a "expr: syntax error"
>
>
expr is an external tool, and expr is the one giving you an error, so it's
not a problem of "bash"
The error may be that your "expr" tool is not the gnu version and thus
doesn't support this syntax.

To get the same result you could use the pattern matching of standard expr
eg matching all the characters not in your set + one:

ind=`expr "$string" :  '[^is]*.'`

with pure (ba)sh, you could use parameter expansion like:

temp=${string%%[is]*}
ind=$(( ${#temp} + 1))

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic