Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Rainer Weikusat Newsgroups: comp.unix.shell,comp.unix.programmer,comp.programming.contests Subject: Re: The First Pure Shell Contest (PUSH): relativepath Date: Tue, 23 Aug 2011 19:52:25 +0100 Lines: 56 Message-ID: <87obzgot92.fsf@sapphire.mobileactivedefense.com> References: <9b7kg7F3njU1@mid.individual.net> <87ty99kxtk.fsf@sapphire.mobileactivedefense.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: individual.net jy8GGUyrvVsRdONZNqb/Wg+hU4zS4y7Wayy0RpR3XhuNu7gQw= Cancel-Lock: sha1:Qa42IbXExluD4exWR3sMUW0rs1o= sha1:M4Et1z5K21yWWc2gtly4OLTr59I= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) Xref: x330-a1.tempe.blueboxinc.net comp.unix.shell:1802 comp.unix.programmer:1183 comp.programming.contests:27 Stephane CHAZELAS writes: > 2011-08-22, 21:15(+01), Rainer Weikusat: >> Jens Schweikhardt writes: >>> The First Pure Shell Contest (PUSH) >>> >>> == Motivation == >>> >>> 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). That you, you'd still had had the chance to boast with your superior knowledge about pecularities of the UNIX(*) standard but in a way which had a chance to be useful to readers. > 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.