Bug? in bash setlocale implementation
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' - -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu' - -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/s uname output: Linux DETH00 3.0.0-15-generic #26-Ubuntu SMP Fri Jan 20 17:23:00 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux Machine Type: x86_64-pc-linux-gnu Bash Version: 4.2 Patch Level: 10 Release Status: release Description: Basically if setting the locale fails variable should not be changed. Consider export LC_CTYPE= bash -c 'LC_CTYPE=ISO-8859-1 eval printf \${LC_CTYPE:-unset}' bash: warning: setlocale: LC_CTYPE: cannot change locale (ISO-8859-1): No such file or directory ISO-8859-1 ksh93 -c 'LC_CTYPE=ISO-8859-1 eval printf \${LC_CTYPE:-unset}' ISO-8859-1: unknown locale unset ksh93 -c 'LC_CTYPE=C.UTF-8 eval printf \${LC_CTYPE:-unset}' C.UTF-8 the advantage being you can check in the script if the local change worked. e.g. LC_CTYPE=ISO-8859-1 [ ${LC_CTYPE:-} = ISO-8859-1 ] || error exit -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJPQ1sbAAoJEKUDtR0WmS05dDEH+wf+Gix7NnSZ6WvwOt6ZRmlv /BXr94coQ1I6ODCXXAG0ExgqNs81gJ58N1xw0nBO/qMpJ1CWv+t5Gc+FP37RK9GK aZbrT6yYAueg/lz58o7hg76oRKVmOpzaYxdquC4dMKa8K1kEdxNyyO4Qxa8a/TNP qLC79kvBl/23CESRomZdhUpOOjTdzhiEo6njLxDmluhzA+U/WsMD1Zp7TJih30gu okkJESAwSsEoo8QIeFbzOFa/qEZQH05SwY0CoYO+OPC0qlNR/Jar9cAJhTpHfxjg bLYXSNlqs5ZCgbmUCypnOWpOktUVPNxpXabNTjWPwAnekEY8Ms4BR6XkG+yuclk= =+Z4p -END PGP SIGNATURE-
Re: Bug? in bash setlocale implementation
On 2/21/12 3:51 AM, John Kearney wrote: Bash Version: 4.2 Patch Level: 10 Release Status: release Description: Basically if setting the locale fails variable should not be changed. I disagree. The assignment was performed correctly and as the user specified. The fact that a side effect of the assignment failed should not mean that the assignment should be undone. I got enough bug reports when I added the warning. I'd get at least as many if I undid a perfectly good assignment statement. I could see setting $? to a non-zero value if the setlocale() call fails, but not when the shell is in posix mode. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
Re: Bug? in bash setlocale implementation
On 02/22/2012 01:52 AM, Chet Ramey wrote: On 2/21/12 3:51 AM, John Kearney wrote: Bash Version: 4.2 Patch Level: 10 Release Status: release Description: Basically if setting the locale fails variable should not be changed. I disagree. The assignment was performed correctly and as the user specified. The fact that a side effect of the assignment failed should not mean that the assignment should be undone. I got enough bug reports when I added the warning. I'd get at least as many if I undid a perfectly good assignment statement. I could see setting $? to a non-zero value if the setlocale() call fails, but not when the shell is in posix mode. Chet ok I guess that makes sense, just ksh93 behavior also makes sense, I guess I can just use some command to check the charset is present before I assign it.