check variable content size in sh script

Teske, Devin Devin.Teske at fisglobal.com
Sat May 18 23:41:41 UTC 2013


On May 18, 2013, at 9:06 AM, Polytropon wrote:

> On Sat, 18 May 2013 11:58:30 -0400, Quartz wrote:
>> 
>>>> newfoo=${foo:0:51}
>>>> 
>>> 
>>> That works for bash, not sh.
>> 
>> Ok granted, but I don't think that ${#foo} is straight sh either, so I 
>> assumed "things bash/tcsh/ksh/whatever accept when running in sh 
>> emulation" were ok.
> 
> By default, there is no bash on FreeBSD, and therefor no emulation
> and "implicit features". :-)
> 
> At least FreeBSD's implementation of sh (which is ash, I think)

dash actually -- the Debian Almquist shell (descendent of NetBSD's ash).
-- 
Devin



> supports the # functionality. From "man sh":
> 
>     ${#parameter}
>             String Length.  The length in characters of the value of
>             parameter.
> 
> And:
> 
>     ${parameter#word}
>             Remove Smallest Prefix Pattern.  The word is expanded to produce
>             a pattern.  The parameter expansion then results in parameter,
>             with the smallest portion of the prefix matched by the pattern
>             deleted.
> 
> Check the chapter "Parameter Expansion" for more surprising
> things that are supported by ye olde /bin/sh. :-)
> 
> 
> 
> -- 
> Polytropon
> Magdeburg, Germany
> Happy FreeBSD user since 4.0
> Andra moi ennepe, Mousa, ...
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"

_____________
The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you.


More information about the freebsd-questions mailing list