syntax error at line 354 : `=~' unexpected in hp unix

506 Views Asked by At

my code is somehow like-

if [[ ! $FIRST=~ ^/ ]] then
            FIRST="${SECOND}/${FIRST}"
fi

and i am getting below error while running the script in HP UNIX- syntax error at line 354 : `=~' unexpected. It seems to work fine in linux. Does anybody has any solution for it?

1

There are 1 best solutions below

0
On

As the comments indicate, the ksh on HP-UX is probably pretty old, so there's no =~ operator.

However, you're just checking that the value begins with a slash, so use glob-style pattern matching:

if [[ $FIRST != /* ]]; then FIRST="$SECOND/$FIRST"; fi

If that doesn't work, use case:

case "$FIRST" in
    /*) : ;;
    *)  FIRST="$SECOND/$FIRST" ;;
esac