bug-bash
[Top][All Lists]
Advanced

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

Re: Problem with small script


From: Greg Wooledge
Subject: Re: Problem with small script
Date: Thu, 18 Feb 2016 12:45:04 -0500
User-agent: Mutt/1.4.2.3i

On Thu, Feb 18, 2016 at 05:58:28PM +0100, balducci@units.it wrote:
> > On Thu, Feb 18, 2016 at 11:06:37PM +0700, Robert Parker wrote:
> > > The script:
> > > #/bin/bash
>      ^ missing ! here
> 
> typo in the shebang?

Yes, nicely done.  I missed that.


On Fri, Feb 19, 2016 at 12:22:20AM +0700, Robert Parker wrote:
> On Thu, Feb 18, 2016 at 11:30 PM, Greg Wooledge <wooledg@eeg.ccf.org> wrote:
> > You MUST check the result of cd.  If it fails but you continue on,
> > you will be operating in the wrong place.
> 
> Fair comment, but this has worked properly in an earlier version that did
> not rely on using *shift.*

It's a separate and more subtle issue.  It's not the cause of the
visible problem.  It's a lurking, insidious bug that will strike in
the future.

> > > while (( "$#" )); do

When you run this command under sh (due to the shebang error, as mentioned
above), it isn't an arithmetic evaluation.  It's just a subshell with
an extra set of inner parentheses.

When you run   ./myscript   in bash, the missing shebang is caught as
an "exec format error" by the kernel.  Bash sees that, and runs it in
another instance of bash.

sudo apparently sees the exec format error, and runs it in sh.  (But you
might want to look into that.  I'm not an expert on sudo.)



reply via email to

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