On 08/21/2012 08:38 AM, Achim Gratz wrote:
> That saves us a fork, so it may even be a net win, on the other hand forking a
> subshell saves us the restore of LC_ALL... How about this, then (which
> doesn't
> fork and handles spaces correctly):
>
> profile_d ()
> {
> for file in /etc/profile.d/*.$1 ; do
> [ -e "${file}" ] && . "${file}"
> done
> unset file
> }
>
> and then calling it like this:
>
> LC_ALL=C profile_d *.sh
Sorry, POSIX requires that to leave LC_ALL set after the function call,
which is not what you want (bash behaves differently according to
whether it was started as bash or sh).
$ ksh -c 'foo=bar; blah() { :; }; foo=baz blah; echo $foo'
baz
$ bash -c 'foo=bar; blah() { :; }; foo=baz blah; echo $foo'
bar
$ sh -c 'foo=bar; blah() { :; }; foo=baz blah; echo $foo'
baz
--
Eric Blake [email protected] +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature

