Web lists-archives.com

Re: Weird shell script behavior in a cron job




	Hi.

On Thu, Aug 31, 2017 at 08:03:51AM -0400, Greg Wooledge wrote:
> On Thu, Aug 31, 2017 at 06:52:28AM +0100, Jonathan de Boyne Pollard wrote:
> > James H. H. Lampert:
> > 
> > > Could it be that |cron| is running it an entirely different shell, that
> > > doesn't understand the |if| statement?
> > > 
> > Despite what others have said, the answer to this question is no.  Whilst
> > you /are/ running two different shells, the problem is not the |if|
> > statement.
> 
> The if statement that he actually *showed* was POSIX-compatible, yes.
> But he later said that changing the shebang fixed his problem, so
> there was some other part of his script that was bash-specific.

No, actually it was quoted part that was bash-specific. Problematic
condition was testing for return code 1 after cd ( '[ "$?" = "1" ]' ).

Compare this:

$ bash -c 'cd foo; echo $?'
bash: line 0: cd: foo: No such file or directory
1

To this:

$ dash -c 'cd foo; echo $?'
dash: 1: cd: can't cd to foo
2

Reco