Calling sh from csh

Polytropon freebsd at
Sun Apr 5 20:26:08 UTC 2020

On Sun, 5 Apr 2020 21:48:37 +0200, Jos Chrispijn wrote:
> Can you tell me how I could find out if a shell script runs on csh or sh 
> and then execute it from within the right shell?

If the shell script declares the required shell in the fist
line, for example


you can simply execute it (given that it has +x execution
permission as required) by

	% ./scriptname

and the correct interpreter will be used.

You can also require bash (in case you're using extended
non-sh functionality) by using


Similarly, executable scripts can call awk, perl or any
other interpreter using the #! mechanism - you simply call
the script by name, the correct interpreter will execute
the script.

In some cases, the filename extension .sh identifies a
shell script as suitable for the sh (or sometimes bash)
shell, so manually calling

	% sh


	% bash

will always work, no matter if a valid #! line is present.

In case no #! is present and the filename has no extension,
it's required to examine the actual content of the script
in order to run the required interpreter. :-)

Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...

More information about the freebsd-questions mailing list