Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.contests > #7 > unrolled thread
| Started by | Jens Schweikhardt <schweikh@schweikhardt.net> |
|---|---|
| First post | 2011-08-19 17:23 +0000 |
| Last post | 2011-08-23 21:56 +0000 |
| Articles | 2 on this page of 22 — 7 participants |
Back to article view | Back to comp.programming.contests
The First Pure Shell Contest (PUSH): relativepath Jens Schweikhardt <schweikh@schweikhardt.net> - 2011-08-19 17:23 +0000
Re: The First Pure Shell Contest (PUSH): relativepath Stephane CHAZELAS <stephane_chazelas@yahoo.fr> - 2011-08-19 18:13 +0000
Re: The First Pure Shell Contest (PUSH): relativepath Jens Schweikhardt <usenet@schweikhardt.net> - 2011-08-19 19:12 +0000
Re: The First Pure Shell Contest (PUSH): relativepath pk <pk@pk.invalid> - 2011-08-19 21:14 +0200
Re: The First Pure Shell Contest (PUSH): relativepath Jens Schweikhardt <usenet@schweikhardt.net> - 2011-08-19 19:29 +0000
Re: The First Pure Shell Contest (PUSH): relativepath pk <pk@pk.invalid> - 2011-08-19 21:37 +0200
Re: The First Pure Shell Contest (PUSH): relativepath Jens Schweikhardt <usenet@schweikhardt.net> - 2011-08-19 20:04 +0000
Re: The First Pure Shell Contest (PUSH): relativepath pk <pk@pk.invalid> - 2011-08-19 22:25 +0200
Re: The First Pure Shell Contest (PUSH): relativepath Jens Schweikhardt <usenet@schweikhardt.net> - 2011-08-19 21:08 +0000
Re: The First Pure Shell Contest (PUSH): relativepath Rainer Weikusat <rweikusat@mssgmbh.com> - 2011-08-19 19:58 +0100
Re: The First Pure Shell Contest (PUSH): relativepath Jens Schweikhardt <usenet@schweikhardt.net> - 2011-08-19 19:23 +0000
Re: The First Pure Shell Contest (PUSH): relativepath Rainer Weikusat <rweikusat@mssgmbh.com> - 2011-08-19 22:18 +0100
Re: The First Pure Shell Contest (PUSH): relativepath Stephane CHAZELAS <Stephane.CHAZELAS@free.fr> - 2011-08-20 20:07 +0000
Re: The First Pure Shell Contest (PUSH): relativepath Jens Schweikhardt <usenet@schweikhardt.net> - 2011-08-21 10:43 +0000
Re: The First Pure Shell Contest (PUSH): relativepath Rainer Weikusat <rweikusat@mssgmbh.com> - 2011-08-21 15:14 +0100
Re: The First Pure Shell Contest (PUSH): relativepath Janis Papanagnou <janis_papanagnou@hotmail.com> - 2011-08-21 18:28 +0300
Re: The First Pure Shell Contest (PUSH): relativepath Stephane CHAZELAS <stephane_chazelas@yahoo.fr> - 2011-08-21 16:19 +0000
Re: The First Pure Shell Contest (PUSH): relativepath Stephane CHAZELAS <stephane_chazelas@yahoo.fr> - 2011-08-21 20:12 +0000
Re: The First Pure Shell Contest (PUSH): relativepath Rainer Weikusat <rweikusat@mssgmbh.com> - 2011-08-22 21:15 +0100
Re: The First Pure Shell Contest (PUSH): relativepath Stephane CHAZELAS <stephane_chazelas@yahoo.fr> - 2011-08-23 18:23 +0000
Re: The First Pure Shell Contest (PUSH): relativepath Rainer Weikusat <rweikusat@mssgmbh.com> - 2011-08-23 19:52 +0100
Re: The First Pure Shell Contest (PUSH): relativepath Stephane CHAZELAS <stephane_chazelas@yahoo.fr> - 2011-08-23 21:56 +0000
Page 2 of 2 — ← Prev page 1 [2]
| From | Rainer Weikusat <rweikusat@mssgmbh.com> |
|---|---|
| Date | 2011-08-23 19:52 +0100 |
| Message-ID | <87obzgot92.fsf@sapphire.mobileactivedefense.com> |
| In reply to | #26 |
Stephane CHAZELAS <stephane_chazelas@yahoo.fr> writes:
> 2011-08-22, 21:15(+01), Rainer Weikusat:
>> Jens Schweikhardt <schweikh@schweikhardt.net> 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.
[toc] | [prev] | [next] | [standalone]
| From | Stephane CHAZELAS <stephane_chazelas@yahoo.fr> |
|---|---|
| Date | 2011-08-23 21:56 +0000 |
| Message-ID | <slrnj588h3.fp4.stephane.chazelas@spam.is.invalid> |
| In reply to | #27 |
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
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.programming.contests
csiph-web