check variable content size in sh script

Tim Daneliuk tundra at tundraware.com
Sat May 18 15:13:50 UTC 2013


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 at tundraware.com
PGP Key:         http://www.tundraware.com/PGP/



More information about the freebsd-questions mailing list