Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ko1nksm opened this issue Jun 15, 2022 · 1 comment

Comments

@ko1nksm
Copy link

ko1nksm commented Jun 15, 2022

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]
@angelhof
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants