Skip to Content.
Sympa Menu

sm-grimoire - Re: [SM-Grimoire] Local abiword spell (script execution in bash)

sm-grimoire AT lists.ibiblio.org

Subject: Discussion of Spells and Grimoire items

List archive

Chronological Thread  
  • From: Seth Woolley <seth AT tautology.org>
  • To: Pierre Abbat <phma AT webjockey.net>
  • Cc: sm-grimoire AT lists.ibiblio.org
  • Subject: Re: [SM-Grimoire] Local abiword spell (script execution in bash)
  • Date: Sun, 19 Jan 2003 16:15:58 -0800 (PST)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi phma,

The shebang line is for figuring out an interpreter when the script is run
directly, when it isn't a bash script itself. If you `. script` or
`source script`, it doesn't need a shebang, nor an execute bit. It just
assumes it's a bash script. Directly running it doesn't have that luxury
(because it could be something else).

In fact you don't need a shebang line if the execute bit is set and it is
a bash script and you are running it from within bash.

try it out for yourself:

==>
cd /tmp
echo '#!/bin/bash
echo "with shebang"' > wshebang
echo 'echo "without shebang"' > woshebang
cp wshebang wshebange
cp woshebang woshebange
chmod u+x wshebange woshebange
./wshebang
./woshebang
./wshebange
./woshebange
. wshebang
. woshebang
. wshebange
. woshebange
source wshebang
source woshebang
source wshebange
source woshebange
rm wshebang woshebang wshebange woshebange
<==

The only two that fail are:
./wshebang
./woshebang

only because they don't have the execute bit set.

PRE_BUILD is run via the ./PRE_BUILD method, and it is a bash script run
from within bash. All you need is the execute bit.

In theory, sorcery could remove that requirement, and run it regardless of
the permissions (with . or source), but it doesn't.

It shouldn't produce an error though. Bash just goes ahead and tries it.
If it were a perl script and you removed the shebang line, it would try to
run it as a bash script, and error out, unless it had the shebang to know
that it was a perl script.

(still in /tmp)
$ echo '
print "perl test\n";' > perltest; chmod u+x perltest; ./perltest; rm perltest
./perltest: line 2: print: command not found
$ echo '#!/usr/bin/perl
print "perl test\n";' > perltest; chmod u+x perltest; ./perltest; rm perltest
perl test
$

Seth

On Sun, 19 Jan 2003, Pierre Abbat wrote:
>
> That made a difference, but why? There is no hashbang line, so attempting to
> execute it should produce an error.
>
> phma

- --
Seth Alan Woolley <seth at tautology.org>, SPAM/UCE is unauthorized
Key id 7BEACC7D = 2978 0BD1 BA48 B671 C1EB 93F7 EDF4 3CDF 7BEA CC7D
Full Key at seth.tautology.org, see www.gnupg.org www.keyserver.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (FreeBSD)

iD8DBQE+Kz/A7fQ833vqzH0RAsRNAKCMRw8VZeFZS9wc0lQq+GhS81EstQCg2zJt
HjNLoMwKSjP+RiJt8XnovdY=
=hXRt
-----END PGP SIGNATURE-----





Archive powered by MHonArc 2.6.24.

Top of Page