Date: Sun, 5 Apr 2020 22:25:39 +0200 From: Polytropon <freebsd@edvax.de> To: Jos Chrispijn <bsduser@cloudzeeland.nl> Cc: freebsd-questions@freebsd.org Subject: Re: Calling sh from csh Message-ID: <20200405222539.f1774965.freebsd@edvax.de> In-Reply-To: <8a13c839-6e0c-8a6e-32bf-b4b42dfaff67@cloudzeeland.nl> References: <8a13c839-6e0c-8a6e-32bf-b4b42dfaff67@cloudzeeland.nl>
next in thread | previous in thread | raw e-mail | index | archive | help
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 #!/bin/sh 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 #!/usr/local/bin/bash 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 scriptname.sh or % bash scriptname.sh 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. :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20200405222539.f1774965.freebsd>