Michael wrote:
Hi,

I am looking for sh/ksh replacement for the following bash command:

$ X="abcdefghi"
$ echo ${X:0:2}
ab


Anyone got an idea?


Michael

How about this:

$ echo ${X%${X#??}}
ab

${X#??} is $X with the first 2 characters (??) removed.

${X%ZZZZZ} is $X with ZZZZZ removed from the end

So we removed from the end everything except the first 2 characters.  Sort of
convoluted but it works.

        - Aner

Reply via email to