Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 May 2013 11:09:02 -0400
From:      Quartz <quartz@sneakertech.com>
To:        Devin Teske <dteske@freebsd.org>
Cc:        Tim Daneliuk <tundra@tundraware.com>, "Teske, Devin" <Devin.Teske@fisglobal.com>, "<freebsd-questions@freebsd.org>" <freebsd-questions@freebsd.org>
Subject:   Re: check variable content size in sh script
Message-ID:  <5197998E.6050200@sneakertech.com>
In-Reply-To: <13CA24D6AB415D428143D44749F57D7201F4D41F@ltcfiswmsgmb26>
References:  <5194F65F.6080503@a1poweruser.com> <5194FB0A.9090400@tundraware.com> <13CA24D6AB415D428143D44749F57D7201F4D41F@ltcfiswmsgmb26>

next in thread | previous in thread | raw e-mail | index | archive | help

> However, if the OP wanted to actually truncate $FOO to 51
> characters:
>
> NEWFOO=$( echo "$FOO" | awk -v max=51 '{print substr($0,0,max)}' )

You don't need all that for a simple truncation/substring, you can do it 
with a direct assignment:

newfoo=${foo:0:51}

The three params here are "variable", "start position" and "length".

______________________________________
it has a certain smooth-brained appeal



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5197998E.6050200>