bug-bash
[Top][All Lists]
Advanced

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

Re: Problem with small script


From: Robert Parker
Subject: Re: Problem with small script
Date: Fri, 19 Feb 2016 01:04:10 +0700


On Fri, Feb 19, 2016 at 12:45 AM, Greg Wooledge <address@hidden> wrote:
On Thu, Feb 18, 2016 at 05:58:28PM +0100, address@hidden 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 <address@hidden> 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.)


You are right on the money!
Under sudo I am running sh
other wise bash
but being not root it has other failures.


But to put it to bed. All the grief came from the missing '!'
Once in place it works.
Under sudo it does run sh but otherwise runs bash.

Glad your eyes are better than mine, and thanks!
Bob



--
The Bundys, Cliven, Ted and Al. Great guys to look up to.

reply via email to

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