Situation: Writing a shell script to do some stuff across multiple shells
Problem: While Bourne-compatible shell scripts (
zsh, etc) are easy to be made portable (just make sure the scripts are
sh compatible and it should run across other Bourne-compatible shells), there are syntax differences compared to those that are not POSIX compatible such as
fish. The script will fail immediately when running on these shells due to syntax errors (expected).
Question: Is there any way to write a script in such a way that it can be executed across all shells regardless of POSIX-compatibility of the individual shells? I cannot think of a way to do so without triggering a syntax error leading to the script exiting itself.