BashScripts.org
http://bashscripts.org/forum/

Chopping first and last chars off of a string.
http://bashscripts.org/forum/viewtopic.php?f=7&t=827
Page 1 of 1

Author:  crouse [ Mon Jun 22, 2009 9:23 am ]
Post subject:  Chopping first and last chars off of a string.

Chopping first and last chars off of a string.

Code:
string="test"
numchar=${#string}
echo ${string: 1:$numchar-2}


an easier way ?
NOT using perl :P

Author:  DarthWavy [ Tue Jun 23, 2009 2:55 am ]
Post subject:  Re: Chopping first and last chars off of a string.

Not that I know of, but you can combine the last 2 lines;

Code:
string="test"
echo ${string: 1:${#string}-2}


The other ways I've considered are all longer.

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com