Re: Was bedeutet [[ expression ]]
- From: Thorsten Kampe <thorsten@xxxxxxxxxxxxxxxx>
- Date: Mon, 2 Mar 2009 10:31:41 +0100
* Juergen P. Meier (Mon, 02 Mar 2009 05:32:32 +0000 (UTC))
Thorsten Kampe <thorsten@xxxxxxxxxxxxxxxx>:
* Juergen Ilse (01 Mar 2009 21:29:35 GMT)
Thorsten Kampe <thorsten@xxxxxxxxxxxxxxxx> wrote:
* Juergen Ilse (27 Feb 2009 11:33:21 GMT)
Hauke Laging <1q2009@xxxxxxxxxxxxxxx> wrote:Richtig. In diesem Falle ist man eben aber nicht auf einen
Du hälst bestimmt das portable KonstruktNein, aber es ist ein vernueftiger workaround (vernueftiger als
[ x"$var" = x ]
für die Krönung der Schöpfung... ;-)
die Nutzung von unportablen Konstruken, die auch nicht besser
funktionieren als dieser Workaround, zumindest ist das meine
Meinung). In manchen Faellen ist man eben auf workaround
angewiesen [...]
Workaround angewiesen.
Doch, sofern man an Portabilitaet interessiert ist. Und damit
koennen wir eigentlich die Diskussion abschliessen: [[ ]] ist
unportabler Mist, auf den man immer verzichten sollte, wenn man
portable Scripte zu schreiben gedenkt, mehr ist dazu nicht zu
sagen.
Sehe ich genauso. Und [ ] ist Mist, auf den man immer verzichten
sollte, wenn man lesbare und robuste Skripte zu schreiben gedenkt.
Freut mich, daß du endlich einmal meiner Meinung bist.
Flasch.
Siehe ISO/IEC Standard 9945 sowie IEEE Standard 1003.1-2001 aka Single
UNIX Specification Version 3 Shell & Utilities -> test
Also, das naechste mal, wenn dir wider hunderte Geisterfahrer entgegen
kommen, fahr einfach mal bei der naechsten Auffahrt von der Autobahn.
Ich sehe hier genau zwei Geisterfahrer und die heißen zufälligerweise
beide "Juergen". Und diese beiden Juergen wollen dieser Newsgruppe allen
Ernstes weißmachen, daß die Entwickler der Korn, Bash und Z Shell
allesamt "Idioten" und "Spasten" sind, die mit "[[ ]]" "Schwachsinn",
"Idiotie" und "Mist" verzapft haben (alles Zitate aus diesem Thread).
Um diesen Dummfug zu widersprechen, zitiere ich einfach drei
Standardwerke:
"(...) there is a newer way of doing conditions. These are instead
delimited by double brackets ([[ ... ]]). They are given special
handling by the shell so that they work better. Unless you need to
support older shells, we would recommend using them instead."
-- "From Bash to Z Shell"
"The [[ ]] construct is the more versatile Bash version of [ ]. This is
the extended test command, adopted from ksh88.
No filename expansion or word splitting takes place between [[ and ]],
but there is parameter expansion and command substitution. (...)
Using the [[ ... ]] test construct, rather than [ ... ] can prevent many
logic errors in scripts. For example, the &&, ||, <, and > operators
work within a [[ ]] test, despite giving an error within a [ ]
construct." -- Advanced Bash Scripting Guide
"Second aside for users of sh: you may remember that tests in sh used a
single pair of brackets, ‘if [ ... ]; then ...’ [...]. The Korn shell
was deliberately made to be different, and zsh follows that. The reason
is that ‘[[’ is treated specially, which allows the shell to do some
extra checks and allows more natural syntax. For example, you may know
that in sh it’s dangerous to test a parameter which may be empty: ‘[
$var = foo ]’ will fail if $var is empty, because in that case the word
is missed out and the shell never knows it was supposed to be there;
with ‘[[ ... ]]’, this is quite safe because the shell is aware there’s
a word before the ‘=’, even if it’s empty. Also, you can use ‘&&’ and
‘||’ to mean logical ‘and’ and ‘or’, which agrees with the usual UNIX/C
convention; in sh, they would have been taken as starting a new command,
not as part of the test, and you have to use the less clear ‘-a’ and ‘-
o’. Actually, zsh provides the old form of test for backward
compatibility, but things will work a lot more smoothly if
you don’t use it." -- "A User’s Guide to the Z-Shell"
Genug gesagt,
Thorten
.
- Follow-Ups:
- Re: Was bedeutet [[ expression ]]
- From: Sven Mascheck
- Re: Was bedeutet [[ expression ]]
- References:
- Re: Was bedeutet [[ expression ]]
- From: Thorsten Kampe
- Re: Was bedeutet [[ expression ]]
- From: Juergen Ilse
- Re: Was bedeutet [[ expression ]]
- From: Thorsten Kampe
- Re: Was bedeutet [[ expression ]]
- From: Juergen P. Meier
- Re: Was bedeutet [[ expression ]]
- Prev by Date: zufällige Zeilen auslesen
- Next by Date: Re: sed aus einer Datei zwei machen
- Previous by thread: Re: Was bedeutet [[ expression ]]
- Next by thread: Re: Was bedeutet [[ expression ]]
- Index(es):
Relevant Pages
|
Loading