Make bootscripts more POSIX compliant

Alexander E. Patrakov patrakov at
Mon Feb 19 23:24:55 PST 2007

Dan Nicholson пишет:
> 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.

Could you please install posh from and test 
whether it reveals any additional breakage?

> 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.

The reason for this sed was that I planned to include translation of boot 
messages and cope with broken shells like ash that don't count characters in 
UTF-8 locales properly (i.e., the reality is that ${#var} is a bashism, even 
though it is mandated by POSIX).

However, since two earlier attempts produced working boot scripts that 
caused absolutely no interest in the LFS community, I revoke the plan, and 
propose to use ${#var}, because it works correctly for English messages (and 
our bootscripts will not produce anything else).

>  	## Figure out the length of what is to be printed to be used
> -        ## for warning messges. 
> -	STRING_LENGTH="`echo "${1}" | sed \
> -		-e 's,.,.,g' -e 'l 1' | grep -c \$`"
> +	## for warning messges. 
> +	STRING_LENGTH=$((${#1} + 1))


Alexander E. Patrakov

More information about the lfs-dev mailing list