Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Stephane CHAZELAS Newsgroups: comp.unix.shell,comp.unix.programmer,comp.programming.contests Subject: Re: The First Pure Shell Contest (PUSH): relativepath Date: Tue, 23 Aug 2011 21:56:52 +0000 (UTC) Organization: A noiseless patient Spider Lines: 62 Message-ID: References: <9b7kg7F3njU1@mid.individual.net> <87ty99kxtk.fsf@sapphire.mobileactivedefense.com> <87obzgot92.fsf@sapphire.mobileactivedefense.com> Injection-Date: Tue, 23 Aug 2011 21:56:52 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="qzG0Li1iwhS8BRIL3GjZtw"; logging-data="6735"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+cquoi8DIUQ91EhEX4y+f+ly2jlhe7b0RnRZ3FzReisg==" User-Agent: slrn/pre1.0.0-18 (Linux) Cancel-Lock: sha1:mApvobMcxFows8Nr84uonA9T9oo= Mail-Copies-To: nobody Xref: x330-a1.tempe.blueboxinc.net comp.unix.shell:1803 comp.unix.programmer:1184 comp.programming.contests:28 2011-08-23, 19:52(+01), Rainer Weikusat: [...] >>>> The shell is not known for powerful string processing. >>> >> [...] >>> echo "<$1> not absolute or canonical" >> [...] >>> while test -n "$fa" -a "$fa" = "$fb"; >> [...] >>> if test -n "$fb" -o "$fa" != "$rb" >> [...] >> >> We may want to add those test cases: >> >> /=/x / 0 ../.. >> / \\\\\\\\ 1 <\\\\\\\\> not absolute or canonical > > No. You 'might' (actually, you should) want to point out the problem > with the two statements above, namely, > > In addition, the string comparison binary primaries '=' and > "!=" shall have a higher precedence than any unary primary. > > http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html > > and maybe even write that the obvious fix is > to rewrite this as > > test -n "$fa" && test "$fa" = "$fb" > > (and similar for the other case). [...] Yes, you're right. But it's repeated so often on cus that - you can't use echo for arbitrary data portably or reliably -> use printf - the -a and -o binary test operators shouldn't be used, or more generally, past 4 arguments to "test"/"[", the behavior is unreliable (-> use &&/|| as you pointed out) that it goes almost without saying. >> What about: >> >> relativepath(){ for i do case $i/ in /|[!/]*|*/./*|*/../*|*?//*|//?*) >> result="<$i> not absolute or canonical";return 1;esac;done >> p=${1%/} r= b=${2%/}/;while :;do case $b in "$p"/*)r=$r${b#"$p"/} >> r=${r%/};result=${r:-.};break;esac;p=${p%/*} r=../$r;done;} > > What about > > dd if=/dev/urandom bs=1 count=1024 | base64 | fold -b -w 26 > > ? > > Granted, it doesn't solve the problem but its as unintelligible as > the gibberish above. You're just jealous because yours is bigger ;-) -- Stephane