1

I meet such error:

expr: syntax error

and my script is:

#!/bin/bash
echo `expr index "sarasara"  a`

how to fix it.

kailee
  • 33
  • 1
  • 5

1 Answers1

2

$ man expr gives this at the end:

According to the POSIX standard, the use of string arguments length, substr, index, or match produces undefined results. In this version of expr, these arguments are treated just as their respective string values.

In other words, macOS' expr does not support index.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • 3
    Using `expr` in Bash is borderline crazy anyway. What are you actually trying to accomplish? `var=${other%%a*}` will produce a substring of `other` whose length indicates how far into `$other` the first `a` was found. – tripleee Dec 10 '18 at 10:19