bug-bash
[Top][All Lists]
Advanced

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

Re: Detecting invocation as /bin/sh ?


From: Greg Wooledge
Subject: Re: Detecting invocation as /bin/sh ?
Date: Fri, 26 Sep 2014 08:14:46 -0400
User-agent: Mutt/1.4.2.3i

On Thu, Sep 25, 2014 at 11:53:18PM -0700, Alexandre Ferrieux wrote:
> Of course, their intention is precisely expressed by the '#!/bin/sh' header

Unfortunately, most people don't actually express an intent when they
use #!/bin/sh.  They just copy some code from a random script they found
somewhere, without understanding what it means.

The number of scripts that use #!/bin/sh but then go on to use Bash
syntax is higher than you might believe.  Whether exported functions are
in that toolset, I couldn't say for sure, but it's likely.  Even in the
#bash channel on IRC we have often advocated constructs like this:

  myfunc() { ...; }
  export -f myfunc
  find . -type f -exec bash -c 'for f; do myfunc "$f"; done' _ {} +

(This is in response to "Why can't I do find -exec myfunc", which is
something of a frequently asked question.)

It's not a stretch of the imagination to suppose that someone has used
exported functions in a #!/bin/sh script on a Linux box where /bin/sh
is a symlink to bash.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]