🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #1286

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

#1286
From: Pim Zandbergen
Date: Sat, 29 Sep 1990 21:55
15 lines
952 bytes
How about 

string=`echo $string | cut -c1`

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

In Korn shell you can use a hack like

string=${string%${string#?}}
-- 
Pim Zandbergen                          domain : pim@cti-software.nl
CTI Software BV                         uucp   : uunet!mcsun!hp4nl!ctisbv!pim
Laan Copes van Cattenburch 70           phone  : +31 70 3542302
2585 GD The Hague, The Netherlands      fax    : +31 70 3512837
Technical Details
Message-ID: <1990Sep29.215559.25098@cti-software.nl>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!hp4nl!ctisbv!pim
References: <1308@ncrwat.Waterloo.NCR.COM> <9737@jpl-devvax.JPL.NASA.GOV> <1990Sep29.193617.25752@iwarp.intel.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!hp4nl!ctisbv!pim
From: pim@cti-software.nl (Pim Zandbergen)
Newsgroups: comp.unix.shell
Subject: Re: Getting at the first char of a string in Bourne shell
Message-ID: <1990Sep29.215559.25098@cti-software.nl>
Date: 29 Sep 90 21:55:59 GMT
References: <1308@ncrwat.Waterloo.NCR.COM> <9737@jpl-devvax.JPL.NASA.GOV> <1990Sep29.193617.25752@iwarp.intel.com>
Organization: CTI Software BV, The Hague, The Netherlands
Lines: 15