Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 May 2013 10:13:15 -0500
From:      Tim Daneliuk <tundra@tundraware.com>
To:        Quartz <quartz@sneakertech.com>
Cc:        Devin Teske <dteske@freebsd.org>, "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:  <51979A8B.8080703@tundraware.com>
In-Reply-To: <5197998E.6050200@sneakertech.com>
References:  <5194F65F.6080503@a1poweruser.com> <5194FB0A.9090400@tundraware.com> <13CA24D6AB415D428143D44749F57D7201F4D41F@ltcfiswmsgmb26> <5197998E.6050200@sneakertech.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 05/18/2013 10:09 AM, Quartz wrote:
>
>> 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}
>

That works for bash, not sh.


-- 
----------------------------------------------------------------------------
Tim Daneliuk     tundra@tundraware.com
PGP Key:         http://www.tundraware.com/PGP/




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?51979A8B.8080703>