How do I (unconditionally) enable unicode support in busybox?

Rich Felker dalias at libc.org
Wed Aug 6 14:58:54 UTC 2014


On Wed, Aug 06, 2014 at 02:51:21PM +0200, Harald Becker wrote:
> Hi James!
> 
> >  The problem is mainly when I use a busybox script
> >as /init inside an initrd (initramfs).  It runs as process 1.
> >The /init script is called directly by the bootloader.  Its
> >environment is controlled by the command line parameters which
> >are set by the *user*.   Worse, in this situation:
> >
> >     export LANG=...
> >
> >DOES NOT WORK for changing subsequent unicode behavior.
> 
> Why shall it not work in this situation? It works for me.
> 
> At the start of the init script I use export LANG=... whatever I
> need. As it is exported it goes to the environment of every process
> started from init script, so UTF-8 support is kept.

Perhaps the issue is that it doesn't work in the initial shell itself
-- for example, glob bracket expressions treat a character as a set of
bytes and match any one of those bytes rather than the character.

> >The
> >behavior is set and locked in by the value of LANG in the initial
> >environment which I don't have control over.
> 
> No control? Why?
> 
> It is usally not needed, but in case you really want to achieve this:
> 
> first init script:
> 
> export LANG=...
> exec /bin/sh second_init_script MAY EVEN SET COMMAND LINE ARGUMENTS
> 
> second init script runs as process 1 with environment set as you like.

I agree this is a good workaround.

> >If exporting worked then the original code I posted would work:
> >
> >     echo -n "$x" | LANG=utf sed 's/./x/g' | wc -c
> 
> Argh ... this kind of exporting makes trouble with ash (and many
> other Unix shells, not all behave correct as expected). Always set
> it at the beginning of your script:

Are you sure? It's well-documented, required by the standard, and has
always worked fine with ash for me. I would consider it the preferred
way of exporting when you don't want to affect subsequent commands or
the state of the current shell, only the current command.

Rich


More information about the busybox mailing list