Make bootscripts more POSIX compliant

Dan Nicholson dbn.lists at gmail.com
Mon Feb 19 22:35:55 PST 2007


After the error the other day with dash and glibc-2.3.6, I decided to
install dash[1] and give it a whirl as /bin/sh. Things went mostly
pretty well with respect to rogue bashisms throughout the system. I've
attached some patches to fix up the bootscripts while consulting the
POSIX spec on shells[2].

First patch is to eliminated "echo -[en]" since it's not always
supported by POSIX shells. I chose to use printf since it was a
builtin in dash. I didn't notice until later that it's not mentioned
in POSIX. And the executable printf is in /usr/bin. We can maintain
the same "echo -[en]" syntax by switching in /bin/echo everywhere,
too.

Second patch is just a tweak for boot_mesg. There's an excessive
pipeline using sed and grep to count the characters in the input
string. Fortunately, POSIX mandates that shells respect ${#var} to
return the length of the string. I chose to add 1 for an extra space
(the old way ended up with 2 spaces for some reason). $((...)) can be
used for arithmetic expansion according to POSIX.

Third patch is a combo because I couldn't keep the diffs separated in
the console script. First fix has to do with &> syntax. This is
equivalent to ">file 2>&1" according to bash(1), and that syntax is
supported by POSIX shells.

The second part has to do with trapping on ERR. Although `set -e' is
supported in POSIX, trapping is only mandated for signals. So, I just
sprinkled a bunch of conditionals through the console script to try to
achieve the same effect as the error trapping.

Let me know what you guys think.

--
Dan

[1] http://gondor.apana.org.au/~herbert/dash/
[2] http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 01-boot-no-echo-e.patch
Type: text/x-patch
Size: 6034 bytes
Desc: not available
URL: <http://lists.linuxfromscratch.org/pipermail/lfs-dev/attachments/20070219/b5d9da27/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 02-boot-builtin-math.patch
Type: text/x-patch
Size: 708 bytes
Desc: not available
URL: <http://lists.linuxfromscratch.org/pipermail/lfs-dev/attachments/20070219/b5d9da27/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 03-boot-redirections-no-err-trap.patch
Type: text/x-patch
Size: 2637 bytes
Desc: not available
URL: <http://lists.linuxfromscratch.org/pipermail/lfs-dev/attachments/20070219/b5d9da27/attachment-0002.bin>


More information about the lfs-dev mailing list