From owner-freebsd-questions@FreeBSD.ORG Sat May 18 16:06:32 2013 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id D5B20228 for ; Sat, 18 May 2013 16:06:32 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx01.qsc.de (mx01.qsc.de [213.148.129.14]) by mx1.freebsd.org (Postfix) with ESMTP id 9E7E6849 for ; Sat, 18 May 2013 16:06:32 +0000 (UTC) Received: from r56.edvax.de (port-92-195-6-62.dynamic.qsc.de [92.195.6.62]) by mx01.qsc.de (Postfix) with ESMTP id 5A8E93D379 for ; Sat, 18 May 2013 18:06:24 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id r4IG6Yxa002408 for ; Sat, 18 May 2013 18:06:34 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Sat, 18 May 2013 18:06:34 +0200 From: Polytropon 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> Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Polytropon List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 May 2013 16:06:32 -0000 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, ...