Date: Fri, 17 Dec 1999 10:52:43 +0100 (CET) From: Oliver Fromme <olli@dorifer.heim3.tu-clausthal.de> To: dl@tyfon.net Cc: freebsd-questions@freebsd.org Subject: Re: Followup: howto tokenize string in sh Message-ID: <199912170952.KAA14689@dorifer.heim3.tu-clausthal.de>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199912170952.KAA14689>
