My script is
#! /bin/bash
v1="hello"
v2="world1"
subIndex=`expr index "${v1}" "${v2}"`
echo $subIndex
and I got the error of "expr: syntax error"
My script is
#! /bin/bash
v1="hello"
v2="world1"
subIndex=`expr index "${v1}" "${v2}"`
echo $subIndex
and I got the error of "expr: syntax error"
It looks like you're using a version of expr
which doesn't have an index
operator.
As you can see in the POSIX standard man page there's no index
in the table of operators. The only mention of index
in that document says that the behaviour is undefined. We can assume that the standardisation process saw that only some implementations supported index
and some or all of the participants did not want to add the additional functionality.
Some other implementations contain additional functionality above and beyond what is specified in the standard. You'll need to install one of these implementations or change your code. GNU expr is one implementation that does have index
, length
, etc..