🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #1301

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

#1301
From: David Smallberg
Date: Mon, 01 Oct 1990 20:13
22 lines
1166 bytes
In article <1990Sep29.215559.25098@cti-software.nl> pim@cti-software.nl (Pim Zandbergen) writes:
>How about 
>In Korn shell you can use a hack like
>
>string=${string%${string#?}}

A fixed-length variable also does the trick:
	typeset -L1 first="$string"
	rest=${string#$first}
Unfortunately, a non- or not clearly documented feature of left- (right-)
justified variables is that leading (trailing) whitespace is stripped off
before the truncating assignment is made, so that
	string="   abc"
	typeset -L1 first="$string"
	echo ">$first<"
yields
	>a<
instead of
	> <
--

-- David Smallberg, das@cs.ucla.edu, ...!{uunet,ucbvax,rutgers}!cs.ucla.edu!das
Technical Details
Message-ID: <39565@shemp.CS.UCLA.EDU>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!decwrl!elroy.jpl.nasa.gov!ucla-cs!oahu!das
References: <9737@jpl-devvax.JPL.NASA.GOV> <1990Sep29.193617.25752@iwarp.intel.com> <1990Sep29.215559.25098@cti-software.nl>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!decwrl!elroy.jpl.nasa.gov!ucla-cs!oahu!das
From: das@oahu.cs.ucla.edu (David Smallberg)
Newsgroups: comp.unix.shell
Subject: Re: Getting at the first char of a string in Bourne shell
Message-ID: <39565@shemp.CS.UCLA.EDU>
Date: 1 Oct 90 20:13:34 GMT
References: <9737@jpl-devvax.JPL.NASA.GOV> <1990Sep29.193617.25752@iwarp.intel.com> <1990Sep29.215559.25098@cti-software.nl>
Sender: news@CS.UCLA.EDU
Organization: UCLA Computer Science Department
Lines: 22