ibara/oksh

=~

Closed this issue · 3 comments

The following works on any shell I have, except oksh:
if [[ "$var" =~ "string" ]]; then echo "1"; else echo "0"; fi

It fails on oksh because oksh does not implement "=~" correctly.

Therefore, for portability, one has to re-write the above as follows:
if [[ "$( echo "$var" | grep "string" )" != "" ]]; then echo "1"; else echo "0"; fi

Scripts may fail when executed under oksh, and rewriting them is demotivating, especially if you have many of them.

Please add "=~" to oksh, and possibly port it back to mainstream sh in OpenBSD.

ibara commented

=~ is a bash extension that zsh has also picked up.
It is neither part of POSIX nor the Korn shell.
If you feel strongly about the inclusion of =~ in oksh, please implement the operator then send your patch to the OpenBSD tech@ mailing list.
This repository is not a staging ground for new ideas. It is a stable repository for other operating systems to obtain the current state of OpenBSD ksh.

It is neither part of POSIX nor the Korn shell.

Then oksh's parser should fail with a syntactic error, instead of accepting "=~" as an operator and letting the script terminate with incorrect results.

However, since oksh IS accepting the operator, then it may rewrite "A =~ B" as "A == *B*" and move on, instead of returning an incorrect result.

ibara commented

Submit a diff to tech@