Register
It is currently Sat Sep 20, 2014 8:00 am

Chopping first and last chars off of a string.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Mon Jun 22, 2009 9:23 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 667
Location: Des Moines, Iowa
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


Top
 Profile WWW  
 PostPosted: Tue Jun 23, 2009 2:55 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
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.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP