There are potentially two questions here:
- May I write scripts in multiple shell variants and use them together?
- May I write a script for one shell variant and have it executed by another shell interpreter?
For the first question:
Yes, as long as the scripts are executed by the shell interpreters that they were written for. Note that it doesn't matter what shell you use for interactive work as long as the scripts have proper
#!-lines and/or are executed with explicit interpreters (e.g.
A script works just like a command that you (or someone else) wrote. Another script could call it no matter in what language it was written (assuming it is executable and has a correct
For the second:
If you write your scripts using only the lowest common denominator in terms of syntax and grammar (which in the case of these three shells is POSIX
sh), you can be fairly certain that they will run under all these shells (but I'm assuming there may be edge cases where one shell's POSIX conformance may be lacking). But why would you have
ksh run an
sh script when you just as well could run it with
bash (and possibly
zsh as well, but I'm not too well versed in that shell) do offer a fair bit of commonality in their extensions to plain
sh, but there are situations where even though the syntax and semantics are seemingly in agreement, strange issues arises from other differences.
In the general case, no, you can not assume that one shell will be able to successfully and correctly run a script written for another shell. For example, a
bash script could use a
ksh script just as if it was any other command, but it should never
Ideally, you should assume that different shells are completely different scripting languages, and write for a particular shell, just as you would not write a piece of Python code and expect it to run under Perl or Ruby (unless it was some contrived polyglot script).