Subject: Re: Bourne shell script help
To: Andy Ruhl <acruhl@gmail.com>
From: Steven M. Bellovin <smb@cs.columbia.edu>
List: netbsd-users
Date: 07/25/2006 20:19:25
On Tue, 25 Jul 2006 12:29:31 -0700, "Andy Ruhl" <acruhl@gmail.com> wrote:

> I'm not much of a scripter, but I need to do something specific and
> I'm hoping someone can help.
> 
> This must be a /bin/sh script for portability, and I need to take 2
> characters off of a 14 or so character string and process them
> separately in order to know how to continue. If there is some common
> unix binary that does it, that would be fine, but it would be
> preferable to do it with built in function I guess. Seems like there
> is something that can easily do this, I just don't know what it is.
> 
> So it would be something like this:
> 
> string=<some 14 character alphanum string>
> 
> firstchar = "$(`cat $string | getfirstchar`)"
> secondchar = "$(`cat $string | getsecondchar`)"
> 
> Or something.
> 
> Any help would be appreciated.
>
See the expr(1) man page:

	first=`expr "$string" : '^\(.\)'`
	second=`expr "$string" : '^.\(.\)'`

		--Steven M. Bellovin, http://www.cs.columbia.edu/~smb