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

Re: My script almost works but spams the terminal its launched from if useing dash.



On 2016-04-16 11:23 -0400, Gene Heskett wrote:

> This bash script has lived in ~/bin for years, but the mention of dash as 
> a replacement for bash made me want to test it with dash by changing the 
> bang line to #!/bin/sh, which is of course (this is wheezy) a softlink 
> to /bin/dash.

FWIW, dash is not a replacement for bash, nor does it aim to be one.

> I am launching it with this command as I don't want it to make any noise 
> at all when its running, just do its job:
>
> bin/mailwatcher 2>&1 >/dev/null &
>
> But when I run it with dash, it doesn't seem to work right, and spams the 
> terminal with its error messages.  One that appears to kill its function 
> is the bashism of using [[ ]] to surround string variables, reported 
> like this:
> bin/mailwatcher: 64: bin/mailwatcher: [[: not found
> bin/mailwatcher: 70: bin/mailwatcher: [[: not found
> bin/mailwatcher: 77: bin/mailwatcher: [[: not found
>
> Which is nice, as I am seeing the reason it fails. Line 64 to illuminate 
> that is:
> 	if [[ ${InMail} = 'gene' ]]
> The other 2 lines are similar except for 'gene'
> The return from inotifywait is what sets the value of ${InMail}
> Can these lines be re-constructed to be valid for either bash or dash?
> If so how?

https://wiki.ubuntu.com/DashAsBinSh has some information how to make
scripts portable.  The checkbashisms command in the devscripts package
can help you detect common non-portable constructions in your scripts.

Cheers,
       Sven


Reply to: