Michael <[EMAIL PROTECTED]> wrote:

> I am looking for sh/ksh replacement for the following bash command:
> 
> $ X="abcdefghi"
> $ echo ${X:0:2}
> ab

echo ab

Yes, I'm being facetious, but without context it's not clear what an
appropriate "replacement" would be.  Traditionally, the regular
expression operator of the expr(1) command has been used for string
processing in shell scripts:

expr "$X" : '\(.\{0,2\}\)'

Frequently, the POSIX sh(1) substring processing to remove the
smallest/largest suffix/prefix pattern is sufficient.

  ${name#pattern}
  ${name##pattern}
  ${name%pattern}
  ${name%%pattern}

-- 
Christian "naddy" Weisgerber                          [EMAIL PROTECTED]

Reply via email to