NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/45430: ash uses argv[0] as $0 for scripts without #!



On Mon, Nov 07, 2011 at 12:10:55AM +0200, Nikolai Kondrashov wrote:
>

> This is what happens on my Galaxy S II (it is only possible to execute using
> busybox):
> 
> $ strings /system/bin/sh | grep NetBSD
> $NetBSD: alias.c,v 1.12 2003/08/07 09:05:29 agc Exp $
> $NetBSD: arith.y,v 1.17 2003/09/17 17:33:36 jmmv Exp $
> $NetBSD: arith_lex.l,v 1.12.6.1 2005/04/07 11:38:58 tron Exp $
> $NetBSD: cd.c,v 1.34 2003/11/14 20:00:28 dsl Exp $
> $NetBSD: error.c,v 1.31 2003/08/07 09:05:30 agc Exp $
> $NetBSD: eval.c,v 1.81.2.1 2005/06/13 22:03:51 tron Exp $
> $NetBSD: exec.c,v 1.37 2003/08/07 09:05:31 agc Exp $
> $NetBSD: expand.c,v 1.68.2.2 2005/04/07 11:37:39 tron Exp $
> $NetBSD: input.c,v 1.39 2003/08/07 09:05:32 agc Exp $
> $NetBSD: jobs.c,v 1.62 2003/12/18 00:56:05 christos Exp $
> $NetBSD: main.c,v 1.48 2003/09/14 12:09:29 jmmv Exp $
> $NetBSD: memalloc.c,v 1.28 2003/08/07 09:05:34 agc Exp $
> $NetBSD: miscbltin.c,v 1.34.2.1 2005/04/07 11:34:20 tron Exp $
> $NetBSD: mystring.c,v 1.16 2003/08/07 09:05:35 agc Exp $
> $NetBSD: options.c,v 1.37 2004/10/30 19:29:27 christos Exp $
> $NetBSD: parser.c,v 1.57 2004/06/27 10:27:57 dsl Exp $
> $NetBSD: redir.c,v 1.29 2004/07/08 03:57:33 christos Exp $
> $NetBSD: show.c,v 1.26 2003/11/14 10:46:13 dsl Exp $
> $NetBSD: trap.c,v 1.31 2005/01/11 19:38:57 christos Exp $
> $NetBSD: output.c,v 1.28 2003/08/07 09:05:36 agc Exp $
> $NetBSD: var.c,v 1.36 2004/10/06 10:23:43 enami Exp $

This is quite old but I can reproduce the issue with NetBSD's /bin/sh,
but only if your script is executed by the shell rather than the kernel.
I.e. if the shell script does not begin with #!/bin/sh.

So:

$ cat /tmp/foo
echo "$0"
$ /bin/sh -c 'PATH=/tmp foo'
foo

evidences the issue, whereas:

$ cat /tmp/foo              
#!/bin/sh

echo "$0"
$ /bin/sh -c 'PATH=/tmp foo'
/tmp/foo

does not.


--
    Roland Dowdeswell                      http://Imrryr.ORG/~elric/


Home | Main Index | Thread Index | Old Index