ash: "source <nonexistent file>" makes ash exit?

Joshua Judson Rosen jrosen at harvestai.com
Mon Mar 18 18:17:42 UTC 2013


On 2013-03-18 05:38, Bernd Petrovitsch wrote:
> Hi!
>
> On Mon, 2013-03-18 at 10:09 +0100, Bastian Bittorf wrote:
>> * Joshua Judson Rosen<jrosen at harvestai.com>  [18.03.2013 09:58]:
>>> failure to dot/source a file can still result in an error-message without
>>> making the shell quit. In order to do that, I had to slightly adjust
>>
>> somebody posted a link to the posix-standard, where explicity is
>> written, a shell must abort when a '. $file' fails. what is your
>> usecase? why is a
>>
>> [ -e "$file" ]&&  . "$file"
>>
>> not ok for you? my usecase was more a "speed" issue, because
>
> The only technical reason against that is the race condition if $file is
> deleted after the existence/read check.

Yes. And there's no way to get around the shell aborting in that case.

There's also an issue of compatibility with scripts written for other shells...:

> Well, since the standard wants that ....

`luckily', the other popular bourne shells (e.g.: bash, dash/ash, ksh) seem to
all actually behave contrary to POSIX on this matter; portable scripts already
have to do ". $file || exit" if they actually want the POSIX behaviour....

So, even ignoring the unfixable race condition, there's a porting effort
required to make shell scripts work with busybox ash as it is.

Given the other places where busybox favours de facto standards over POSIX
(e.g.: ls reports in 1-kB block rather than 512-byte blocks, command
  option-parsing doesn't stop at the first non-option parameter),
doing the same in dotcmd() seems reasonable.

Walter Harms mentioned `$POSIXLY_CORRECT', which is how the GNU programs
handle these `POSIX says one thing but everyone actually does this other thing'
cases; I was somewhat surprised to find that POSIXLY_CORRECT already
occurs some other places in busybox, so maybe Walter's right to suggest that.
Or maybe Mike Frysinger's suggestion to conditionalise the behaviour with
`#if ENABLE_ASH_BASH_COMPAT' is correct. Here's a patch that does both ;)

-- 
"Don't be afraid to ask (λf.((λx.xx) (λr.f(rr))))."
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ash-dotcmd-nofile-nonfatal-posixable.patch
Type: text/x-patch
Size: 2133 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20130318/d277a1be/attachment.bin>


More information about the busybox mailing list