Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • Can you look at my post again and see if you have a solution for the followup question? thanks! Commented May 9, 2012 at 17:40
  • You can use cut to cut characters too! cut -c1 for example.
    – Matt K
    Commented May 9, 2012 at 17:59
  • 2
    Although this is very simple to read and write, is a very slow solution because forces you to read twice the same data ($STR) ... if you care of your script performace, the @anubhava solution is much better
    – FSp
    Commented Nov 27, 2012 at 10:26
  • 2
    Apart from being an ugly last-resort solution, this has a bug: You should absolutely use double quotes in echo "$STR" unless you specifically want the shell to expand any wildcards in the string as a side effect. See also stackoverflow.com/questions/10067266/…
    – tripleee
    Commented Jan 25, 2016 at 6:47
  • 1
    You're right about double quotes of course, though I did point out this solution wasn't general. However I think your assessment is a bit unfair - for some people this solution may be more readable (and hence extensible etc) than some others, and doesn't completely rely on arcane bash feature that wouldn't translate to other shells. I suspect that's why my solution, though less elegant, continues to get votes periodically...
    – Rob I
    Commented Feb 10, 2016 at 13:57