Getting at the first char of a string in Bourne shell

Leslie Mikesell les at chinet.chi.il.us
Tue Oct 2 13:34:07 AEST 1990


In article <1990Sep29.215559.25098 at cti-software.nl> pim at cti-software.nl (Pim Zandbergen) writes:
>How about 

>string=`echo $string | cut -c1`

>I don't think the Bourne shell can do this without executing
>an external command.

There's always something like:

string=foo
for i in a b c d e f g (you know the rest...)
do
case "$string"
 in
$i*) first=$i
 break
 ;;
esac
done
echo $first

Les Mikesell
  les at chinet.chi.il.us



More information about the Comp.unix.shell mailing list