Getting at the first char of a string in Bourne shell

Scott Yelich scott at tab00.larc.nasa.gov
Mon Oct 1 13:21:41 AEST 1990


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

Uh, it CAN be done... the question is whether you want to fork another
process or have a massive hack to accomplish something which is
actually a minimal function (Lets pass a lisp function to get the
first letter to emacs... etc).

As an EXAMPLE only, and an example which YOU can expand...

STRING="STRING"
set +F
case "$STRING" in
  S* ) FIRST=S;;
esac
echo "The first letter of \`\`$STRING'' is \`\`$FIRST\'\'

Now, do you REALLY want to do this?
--
Signature follows. [Skip now]

 -----------------------------------------------------------------------------
 Scott D. Yelich                         scott@[xanth.]cs.odu.edu [128.82.8.1]
 After he pushed me off the cliff, he asked me, as I fell, ``Why'd you jump?''
 Administrator of:    Game-Design requests to <game-design-request at cs.odu.edu>
 ODU/UNIX/BSD/X/C/ROOT/XANTH/CS/VSVN/
 -----------------------------------------------------------------------------



More information about the Comp.unix.shell mailing list