|Subject:||Re: Problem with small script|
|Date:||Fri, 19 Feb 2016 01:04:10 +0700|
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
> > > 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.)
|[Prev in Thread]||Current Thread||[Next in Thread]|