Note that if the script is sourced (e.g. . /path/to/script.sh) rather than run as an executable file then it will be run in the current shell.
True.
With regard to the original post, if the script is sourced, even if the shebang is present, it is never used.
Regards,
Alister
---------- Post updated at 10:02 AM ---------- Previous update was at 09:39 AM ----------
Quote:
Originally Posted by 244an
Is that correct?
I'm on FreeBSD...
It should be correct. It's a fundamental and standardized behavior. From your description, it sounds like you are explicitly passing the script to different shells, but I can't be certain. You did not clearly and unambiguously state the exact commands that you used to create your script and run it. Please do so.
For version info, you should be able to get it from uname -a.
Regards,
Alister
---------- Post updated at 10:24 AM ---------- Previous update was at 10:02 AM ----------
The following excerpts are from the current version of FreeBSD's libc. The most relevant bits have been highlighted:
From FreeBSD CVS - src/lib/libc/gen/exec.c
execvpe(3) calls execve(2) (through a libc wrapper). If the system call fails with ENOEXEC, that means that an executable file was found but its format is not recognized. This happens if the file is a foreign binary or if it's a shell script without a shebang. execvpe(3) then reattempts to execve a bourne shell with the unrecognized file as its first argument.
I also took a look at glibc and they too share the same implementation design. execlp and execvp wrap execvpe. execvpe takes care of checking errno after execve, retrying with /bin/sh if appropriate. They both use _PATH_BSHELL to point to /bin/sh.
Hi,
I am currently writing BASH shell scripts. I am using BASH on a Powerbook G4 running Leopard. Could somebody please explain the difference between
#!/bin/bash and #!/bin/sh?
I have been using the latter (#!/bin/sh), and things have been working fine. But is that the correct one to use... (9 Replies)
Do we need to include the exclamatory mark in the shebang line??:confused:
What if we dont include it??:eek:
Actually what shebang line implies when we run a script??
shebang line--> #!/bin/ksh :p (6 Replies)
Can any one tell me how to replace a shebang line of a file using sed?
Eg: If a file contains the following shebang line
#!C:/InstantRails/ruby/bin/ruby
I would like to replace it with
#!/usr/local/bin/ruby
The shebang line of the file can be obtained from the command
cat... (3 Replies)
*** EDIT: I found something close to my solution under an IIS 7 Module Handle.*****
(Non-Homework question, simply an ease of use one)
Odd question here and maybe its my newness to cgi/Perl, but is it possible to have 2 shebang lines?
I write an test a ton of my homework code on my windows... (1 Reply)
Hi,
I always thought that #!/usr/bin/ksh means that the script would be executed in korn shell i.e. when we'll execute the script with this line as the very first line then the shell spawns a korn shell (in this case as we are using #!/usr/bin/ksh ) and the script gets executed.
But I am... (7 Replies)
Hi,
I have a trivial question to ask, I am seeing in some shell scripts the '-' (hyphen) character following the first line of shell script (i.e) the shebang notation as follows:
#!/bin/sh -
#! /bin/bash -
what does the hyphen signify? What will happen if it is not given explicitly? (2 Replies)
Hi ,
I know about the shebang line in shell scripting. Just want to know whether is there any difference in execution of the program by keeping and not keeping the shebang line. Because without shebang line also the script is working. correct me if am wrong. Any help on this will be helpful (5 Replies)