For example, if I have example.sh with following content
. non-existing.sh
echo 'continues!'
Then I source the script in an interactive session with . ./example.sh, should I see “continues!” in the terminal? The standard specifies
If no readable file is found, a non-interactive shell shall abort; an interactive shell shall write a diagnostic message to standard error, but this condition shall not be considered a syntax error.
I understand that if I . non-existing.sh the session should continues, but I’m not sure how it applies to nested sources. In Bash it continues running after printing the error message (even with set -o posix); in Dash it aborts current script (example.sh). I wonder whether this is Bash not compliant to POSIX, or is this unspecified (implementation-defined behavior) in POSIX?
example.sh, which sourcednon-existing.sh, so this is two-level nested. – Franklin Yu Dec 10 '20 at 07:56bashis non-POSIX compliant. This has recently been discussed in the POSIX teleconference. – schily Jan 31 '21 at 14:18set -eat first? – Feb 19 '21 at 07:39set -emeans, but it’s not required for switching to POSIX mode. I specifically don’t wanterrexitin this script. POSIX behavior should have been well-defined, with or withoutset -e. – Franklin Yu Feb 19 '21 at 17:10