From owner-freebsd-questions@FreeBSD.ORG Sat Apr 9 16:47:45 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 93AC91065670 for ; Sat, 9 Apr 2011 16:47:45 +0000 (UTC) (envelope-from Devin.Teske@fisglobal.com) Received: from mx1.fisglobal.com (mx1.fisglobal.com [199.200.24.190]) by mx1.freebsd.org (Postfix) with ESMTP id 5FFF08FC19 for ; Sat, 9 Apr 2011 16:47:45 +0000 (UTC) Received: from SBHFISLREXT03 ([10.132.254.62]) by SCSFISLTC01 (8.14.3/8.14.3) with ESMTP id p39GlGTM028081; Sat, 9 Apr 2011 11:47:16 -0500 Received: from SBHFISLTCGW04.FNFIS.COM (Not Verified[10.132.248.123]) by SBHFISLREXT03 with MailMarshal (v6, 5, 4, 7535) id ; Sat, 09 Apr 2011 11:47:25 -0500 Received: from SBHFISLTCGW07.FNFIS.COM ([10.132.248.135]) by SBHFISLTCGW04.FNFIS.COM with Microsoft SMTPSVC(6.0.3790.4675); Sat, 9 Apr 2011 11:47:16 -0500 Received: from [127.0.0.1] ([10.132.254.136]) by SBHFISLTCGW07.FNFIS.COM over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Sat, 9 Apr 2011 11:47:16 -0500 References: <824253.34690.qm@web113616.mail.gq1.yahoo.com> In-Reply-To: <824253.34690.qm@web113616.mail.gq1.yahoo.com> Mime-Version: 1.0 (iPad Mail 8G4) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Message-Id: <90087016-3918-4F74-A768-67023E3C2B85@vicor.com> X-Mailer: iPad Mail (8G4) From: Devin Teske Date: Sat, 9 Apr 2011 09:47:16 -0700 To: Dino Vliet X-OriginalArrivalTime: 09 Apr 2011 16:47:16.0396 (UTC) FILETIME=[C8966EC0:01CBF6D5] Cc: "freebsd-questions@freebsd.org" Subject: Re: shell programming question: help with expr command X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Apr 2011 16:47:45 -0000 On Apr 9, 2011, at 6:31 AM, Dino Vliet wrote: > Hi folks, > I'm having trouble with a little shell script. Can somebody explain me wh= y I get 3 times "expr: syntax error" in my console after I run this little= script? >=20 > #! /usr/local/bin/bash > # testscript=20 >=20 > var1=3D"trees.J48" #other value will be rules.Jrip, rules.DecisionTable > len=3D${#var1} > ind=3D`expr index $var1 s` > pos=3D`expr $len - $ind` > out=3D`expr substr $var1 $ind $pos`=20 >=20 > I would expect (and want the following to happen): >=20 > $ind should contain 6 > $pos should contain 3 > $out should contain J48 (other values will have to be Jrip,DecisionTable) >=20 > Can anyone help me with this? This would be a /bin/sh compatible (read: portable) way to accomplish the a= bove: #!/bin/sh # testscript=20 var1=3D"trees.J48" #other value will be rules.Jrip, rules.DecisionTable len=3D${#var1} ind=3D`echo "$var1" | awk '{print index($0,"s")+1}'` pos=3D$(( $len - $ind )) out=3D`echo "$var1" | awk -vind=3D"$ind" -vpos=3D"$pos" '{print substr($0,i= nd+1,pos)}'` Though, there are certainly easier ways to get at what it is that I assume = your after: #!/bin/sh # testscript var1=3D"trees.J48" #other value will be rules.Jrip, rules.DecisionTable out=3D"${var1##*.}" --=20 Devin >=20 > Thanks >=20 > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.o= rg" _____________ The information contained in this message is proprietary and/or confidentia= l. If you are not the intended recipient, please: (i) delete the message an= d all copies; (ii) do not disclose, distribute or use the message in any ma= nner; and (iii) notify the sender immediately. In addition, please be aware= that any message addressed to our domain is subject to archiving and revie= w by persons other than the intended recipient. Thank you. _____________