🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #1276

Re: Getting at the first char of a string in Bourne shell

#1276
From: Larry Wall
Date: Fri, 28 Sep 1990 23:59
23 lines
1069 bytes
In article <1308@ncrwat.Waterloo.NCR.COM> ken@images1.Waterloo.NCR.COM (Ken Braithwaite) writes:
: I am trying to peel off one at a time the letters from a variable
: in the Bourne shell, ie from Bourne get B and ourne.
: How can I do this?

A fairly efficient way would be

    echo "Bourne" | SOMETHING | while read line; do
	...
    done

where SOMETHING is one of

    sed 's/\(.\)/\1\
    /g
    s/\n$//'

    perl -pe 'chop; s/./$&\n/g'

There are lots of other ways.

Larry Wall
lwall@jpl-devvax.jpl.nasa.gov
Technical Details
Message-ID: <9737@jpl-devvax.JPL.NASA.GOV>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall
References: <1308@ncrwat.Waterloo.NCR.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall
From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall)
Newsgroups: comp.unix.shell
Subject: Re: Getting at the first char of a string in Bourne shell
Message-ID: <9737@jpl-devvax.JPL.NASA.GOV>
Date: 28 Sep 90 23:59:11 GMT
References: <1308@ncrwat.Waterloo.NCR.COM>
Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall)
Organization: Jet Propulsion Laboratory, Pasadena, CA
Lines: 23