pash icon indicating copy to clipboard operation
pash copied to clipboard

Incompatibility with POSIX sh returns incorrect results. (Does pash only work with bash?)

Open ko1nksm opened this issue 2 years ago • 1 comments

I noticed that pash depends on bash, as opposed to pash, which only supports POSIX syntax. This is because pash relies on the bashism's export -f. (Am I corerct?)

The default behavior of bash differs slightly from POSIX sh. The following code produces different output on pa.sh.

#!/bin/sh
set -e
output=$(false; echo "should not be output")
echo "$output"

On Ubuntu /bin/sh is dash (POSIX sh).

$ ./test.sh
(no output)

$ pa.sh ./test.sh
should not be output

This problem can be corrected by running shopt -s inherit_errexit or set -o posix.

However, if executed in a different shell than the expected shell incompatibilities between shells can be problematic. For example, the following code also returns different results. Both of these behaviors are POSIX-compliant and cannot be fixed by set -o posix.

#!/bin/sh
echo "[\t]"
$ ./test.sh
[	]

$ pa.sh ./test.sh
[\t]

ko1nksm avatar Jun 15 '22 13:06 ko1nksm

You are correct, PaSh executes everything on top of bash, and aims for compatibility with bash. Furthermore, we have only tested compatibility with bash without the set -o posix.

In principle, it should be possible to build execution backends for different shells, but PaSh's JIT engine (https://github.com/binpash/pash/blob/main/compiler/pash_runtime.sh) would need to be modified accordingly.

angelhof avatar Jun 17 '22 21:06 angelhof