Update: The issue turned out to be that the script file had Windows-style line endings (\r\n
) rather than what bash
- and Unix utilities in general - expect (\n
only), as @devnull suspected.
Normally, sh
is symlinked to bash
on CentOS, so your script SHOULD work fine.
(As an aside: any POSIX-compliant shell should work with the specific sample script in your question, however.
General caveat: As @Scrutinizer points out in a comment, invoking bash
as sh
implies subtle changes in behavior - see http://www.gnu.org/software/bash/manual/html_node/Bash-POSIX-Mode.html (*) - though bashisms still work).
Generally, however, if you're invoking a bash
script, it's both conceptually clearer and safer to invoke it with bash
- given that sh
could have been redefined to invoke a different shell.
Of course, you can run chmod +x PreStartupCommands.sh
to make your script executable by itself, which makes the problem go away (assuming the problem is related to what executable is processing the script).
(*) Invoking bash
as sh
on OSX has additional implications (since sh
is a separately compiled executable rather than a symlink there), namely that shell option xpg_echo
is turned ON by default, and that in the absence of $FCEDIT
, ed
is used (without checking for $EDITOR
, as bash
normally does).