Date: Sat, 18 May 2013 18:06:34 +0200 From: Polytropon <freebsd@edvax.de> To: freebsd-questions@freebsd.org Subject: Re: check variable content size in sh script Message-ID: <20130518180634.9e5fd3c2.freebsd@edvax.de> In-Reply-To: <5197A526.7020302@sneakertech.com> References: <5194F65F.6080503@a1poweruser.com> <5194FB0A.9090400@tundraware.com> <13CA24D6AB415D428143D44749F57D7201F4D41F@ltcfiswmsgmb26> <5197998E.6050200@sneakertech.com> <51979A8B.8080703@tundraware.com> <5197A526.7020302@sneakertech.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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) 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, ...
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130518180634.9e5fd3c2.freebsd>