bash question

Rick Delaney rick-h4KjNK7Mzas at public.gmane.org
Thu Aug 12 13:04:06 UTC 2004


On Wed, Aug 11, 2004 at 12:46:54AM -0400, Peter L. Peres wrote:
> 
> I was trying to use ${foo:-1:2} in bash but it does not work (it is 
> supposed to extract the last 2 chars in $foo. However ${foo:${#foo}-2:2} 
> works as expected.

Try ${foo: -1:2} (note the space) to help bash distinguish from the
${foo:-show me when foo is null} case.  Also, if you want the last two
characters then it should be ${foo: -2:2}.

HTH,

-- 
Rick Delaney
rick-h4KjNK7Mzas at public.gmane.org
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list