>> I would like to set the LANG conditionally depending on whether I am
>> at the console (where UTF encoding works) or whether I am logging in
>> remotely (e.g., putty over SSH or cygwin) where UTF is not properly
>> supported.
>> Currently, I am using the following code in my .bashrc file:
>> if [[ !( `tty` == /dev/tty* || $DISPLAY == :0 || $DISPLAY == :0.0 ) ]]; then
>> export LANG=C
>> fi
>> This is a bit of a hack and is not as precise as I would like.
>> For example, it seems that the extglob shopt doesn't work in .bashrc,
>> so I can't use the more precise regexp /dev/tty+[0-9]. Similarly, I
>> would prefer to use a single regexp for the display matching, such as :0?(.0)
> Use 'expr'. will solve all your problem. beside, it will be /bin/sh
> compatible also (your '[[' will cease to work when bash is not
> normally available, say Solaris).
With a POSIX-type shell such as bash, there is little reason to
use expr. Most versions of Unix, including Solaris, will have a
POSIX shell, usually ksh on commercial *nixes. Besides, Jeffrey
wants to put it in .bashrc.
In this instance, I wouldn't try to cram all the tests into a
single line; it will make the script much harder to modify or
debug should that become necessary.
I'd probably use 2 case statements that make the logic clear
(adjust to taste):
case `tty` in
/dev/tty[0-9]*) ;;
*) LANG=C ;;
esac
case $DISPLAY in
:0|:0.0) ;;
*) LANG=C ;;
esac
export LANG
This also has the advantage that it will run on any Bourne-type
shell (/bin/sh) should the need arise.
Quote:> A simple example to get you started:
> $ v="version1234."
> $ expr $v : '.*n\([0-9][0-9]*\).*'
> 1234
Most string manipulation can be done in a POSIX shell without
needing any external command.
--
Chris F.A. Johnson http://cfaj.freeshell.org
===================================================================
My code (if any) in this post is copyright 2002, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License