Re: Extracting a character from a string



Stu wrote:
Im looking for a way to get a character from a string using KSH. For
example, in perl code I can do this:

my($first_char) = substr($string, 0, 1); # Get the first
character from the string
my($second_char) = substr($string, 1, 1); # Get the second
character from the string.

Is there something similiar I can do in kSH.

I don't know if this is a bashism but maybe you try:

fubar="foo bar"
echo ${fubar:1:1}

yield "f"


Thanks in advance to all who answer this post


HTH,
--
Stephan Grein, <stephan at stephan minus rockt dot de>
https://stephan-rockt.de
GnuPG-Key-ID: 0xF8C275D4
FingerPrint: 5B6F 134A 189B A24D 342B 0961 8D4B 0230 F8C2 75D4
.



Relevant Pages