Subject: Re: Bourne shell script help
To: Andy Ruhl <acruhl@gmail.com>
From: Matt Thomas <matt@3am-software.com>
List: netbsd-users
Date: 07/25/2006 12:32:02
Andy Ruhl 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.
> 
> Andy

firstchar=`echo "$string" | cut -c 1`
secondchar=`echo "$string" | cut -c 2`