home | list info | list archive | date index | thread index

[OCLUG-Tech] Shell scripting: how to loop through characters of a string?


  Curious about the best(?) way to do some simple operations in a shell script
that I would *prefer* to be POSIX-compliant, so here's the first question --
how to loop through the individual characters of a string?

  I just stumbled across this solution I'd never heard of:

  $ echo "rday" | grep -o .     [-o,--only-matching option to grep]
  r
  d
  a
  y
  $

so, obviously, I can stick that command in a "for" loop in my script.
I'm not sure I need anything simpler or more elegant than that, but is
there anything even cooler?

  More shell questions coming shortly ...

rday