RFC: 3 shells (ash, dash, bash), 3 different behaviours
Cristian Ionescu-Idbohrn
cristian.ionescu-idbohrn at axis.com
Fri Mar 14 11:35:00 UTC 2014
On Fri, 14 Mar 2014, ibid.ag at gmail.com wrote:
> On Fri, Mar 14, 2014 at 12:24:51AM +0100, Cristian Ionescu-Idbohrn wrote:
> > On Thu, 13 Mar 2014, Cristian Ionescu-Idbohrn wrote:
> > >
> > > It's explained here:
> > >
> > > http://pubs.opengroup.org/onlinepubs/009695399/utilities/sh.html
> > >
> > > IFS
> > >
> > > (Input Field Separators.) A string treated as a list of
> > > characters that shall be used for field splitting and to split
> > > lines into words with the read command. See Field Splitting.
> > > If IFS is not set, the shell shall behave as if the value of
> > > IFS were <space>, <tab>, and <newline>.
> > > Implementations may ignore the value of IFS in the environment
> > > at the time sh is invoked, treating IFS as if it were not set.
> > >
> > > What bothers me is the last phrase:
> >
> > Reading this again:
> >
> > > Implementations may ignore the value of IFS in the environment
> > > at the time sh is invoked, treating IFS as if it were not set.
> >
> > My mother tongue isn't english, but what I make of it is that the
> > shell may ignore an environment IFS set outside a shell(script)?.
> > Thoughts?
>
> Correct.
>
> If you use either of these:
> export IFS=" -_"; sh #or ./script.sh ...
>
> IFS=" -_" sh
>
> the shell is _permitted_ (but not required) to ignore the value of IFS.
>
> The reverse sequence,
>
> sh
> $ IFS=" -_"
>
> cannot be ignored, however.
>
> So the shell could unconditionally unset IFS on start.
Right. Then the only "unexpected behaviour" ash, bash and dash show
is that after activelly unsetting IFS, the shell produces the error:
IFS: parameter not set
when attemting to access the IFS value, although word splitting will
internally still work, as the shell will fall back on an:
IFS=<space><tab><newline>
I guess I'm ok with that.
(see even attached improved example script).
Cheers,
--
Cristian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: IFS-and-busybox-ash.example.sh
Type: application/x-sh
Size: 501 bytes
Desc:
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20140314/4160b590/attachment.sh>
More information about the busybox
mailing list