dash doesn't support switching LC_* during a script/session

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey.

I've noticed that dash (like klibc-utils sh - but unlike bash or
busybox sh) doesn't seem to support the follwoing:

Switching LC_*/LANG variables during a script/session and have that
change take effect on the very same script/session.


Consider the following check for this:
# check whether LC_* switch works in one script

#in UTF-8 the following is U+220B CONTAINS AS MEMBER
bs="$(printf '\342\210\213' )"

export LC_ALL=C.UTF-8
len1=${#bs}

export LC_ALL=C
len2=${#bs}

printf '%s %s\n' "${len1}" "${len2}"

# should return "1 2"



Now I'm not really sure whether or not POSIX mandates that this should
work or whether it's unspecified.
I'd kinda vaguely guess that it actually must be supported because of:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_05_03

Quoting:
"The following variables shall affect the execution of the shell:
[...]
LANG
[...]
LC_ALL
[...]
"

And it really says: the following variables (and the chapter is "Shell
Variables") and "shall affect the execution of the shell".
It does not say, "environment variables" (in the sense that it would
have been just set once when the shell was invoked).


Even if POSIX wouldn't mandate this behaviour, I'd kindly ask to
support it, given that it's a requirement for the (apparently) only
really portable way of implementing/hacking command substitution that
keeps trailing newlines (see
e.g. https://unix.stackexchange.com/a/383390/474076).


Thanks,
Chris.



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux