From owner-freebsd-questions Fri Dec 17 1:52:47 1999 Delivered-To: freebsd-questions@freebsd.org Received: from dorifer.heim3.tu-clausthal.de (dorifer.heim3.tu-clausthal.de [139.174.243.252]) by hub.freebsd.org (Postfix) with ESMTP id C27F115122 for ; Fri, 17 Dec 1999 01:52:44 -0800 (PST) (envelope-from olli@dorifer.heim3.tu-clausthal.de) Received: (from olli@localhost) by dorifer.heim3.tu-clausthal.de (8.8.8/8.8.8) id KAA14689; Fri, 17 Dec 1999 10:52:43 +0100 (CET) (envelope-from olli) Date: Fri, 17 Dec 1999 10:52:43 +0100 (CET) From: Oliver Fromme Message-Id: <199912170952.KAA14689@dorifer.heim3.tu-clausthal.de> To: dl@tyfon.net Subject: Re: Followup: howto tokenize string in sh Cc: freebsd-questions@freebsd.org Organization: Administration TU Clausthal Reply-To: freebsd-questions@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Newsreader: TIN [version 1.2 RZTUC(3) PL2] Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Dan Larsson wrote in list.freebsd-questions: > I know a echo "path../../is/relative" | awk -F/ '{print $n}' prints one token but I don't > know how to evaluate all with ".." and return true if ".." is found in a token. If you just want to know if a variable in sh contains the substring "..", this is easy: case "$var" in *..*) echo 'I contain ".."!' ;; *) echo 'I do not contain "..".' ;; esac That solution is even quite efficient, because it does not require to exec any external programs ("case" is an sh- builtin). However, it will also catch things like "/bla/foo..bar/baz" which is probably not what you want. The following is more accurate: case "$var" in ../*|*/..|..|*/../*) echo 'Bingo!' ;; *) echo 'Nope.' ;; esac This solution will find any path that contains ".." as a component. HTH. Regards Oliver Fromme -- Oliver Fromme, Leibnizstr. 18/61, 38678 Clausthal, Germany (Info: finger userinfo:olli@dorifer.heim3.tu-clausthal.de) "In jedem Stück Kohle wartet ein Diamant auf seine Geburt" (Terry Pratchett) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message