Veröffentlicht 21. Mai 200322 j Hallo, folgende Frage wird für euch UNIX-Gurus sicherlich leicht zu beantworten sein: warum verwendet man hier Anführungszeichen if [ "$success" -eq 0 ] hier aber nicht: if [ $yesno != "y" ] ist es so, dass man beim Vergleich von Zahlen (der ja mit -eq stattfindet) die Variable immer in Anführungszeichen einschließen muss - oder hat es einen anderen Grund? Gruß, Technician P.S.: Ich habe derzeit keinen UNIX-Zugriff, deshalb meine Frage. Ansonsten wäre es sicherlich ein leichtes, das einfach auszuprobieren!
21. Mai 200322 j Ich bin zwar auch nur ein Linux Newbie, aber hab etwas gefunden. (Google - mehr sag ich nicht ) using Quotes to enclose your variables Sometimes, it is a good idea to protect variable names in double quotes. This is usually the most important if your variables value either (a) contains spaces or ( is the empty string. An example is as follows: #!/bin/bash X="" if [ -n $X ]; then # -n tests to see if the argument is non empty echo "the variable X is not the empty string" fi This script will give the following output: the variable X is not the empty string Why ? because the shell expands $X to the empty string. The expression [ -n ] returns true (since it is not provided with an argument). A better script would have been: #!/bin/bash X="" if [ -n "$X" ]; then # -n tests to see if the argument is non empty echo "the variable X is not the empty string" fi In this example, the expression expands to [ -n "" ] which returns false, since the string enclosed in inverted commas is clearly empty. http://pegasus.rutgers.edu/~elflord/unix/bash-tute.html
Archiv
Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.