[ "$UID" = "0" ] || su -

F

flugopa

Was ist an den nachfolgenden Skript falsch?

Code:
# cat erstelle.sh
cat << EOF > ergebnis
[ "$UID" = "0" ] || su -
EOF
chmod +x ergebnis

erwartet
Code:
# cat ergebnis 
[ "$UID" = "0" ] || su -

gekommen
Code:
# cat ergebnis 
[ "0" = "0" ] || su -
 
Mach doch mal
Code:
[ "\$UID" = "0" ] || su -
... sonst wird die UID schon beim Auswerten des Here-Documents innerhalb der "-Quotes ausgewertet.

Gruss
 
Vielen Dank floyd62, für die schnelle und richtige Antwort.
 
Du kannst auch einfach (statt jedes einzelne Dollarzeichen einzeln zu escapen) Variablen-Interpolation "global" innerhalb des here-docs ausschalten, indem du den Begrenzer in single-quotes (oder irgendwelche quotes, aber ich rate zu single-quotes) packst:
Code:
       The format of here-documents is:

              <<[-]word
                      here-document
              delimiter

       No  parameter expansion, command substitution, arithmetic expansion, or pathname expansion is performed
       on word.  [b]If any characters in word are quoted, the delimiter is the result of quote removal  on  word,
       and  the lines in the here-document are not expanded.[/b]  [i]If word is unquoted, all lines of the here-docu‐
       ment are subjected to parameter expansion, command substitution, and arithmetic expansion.[/i]  In the lat‐
       ter  case,  the character sequence \<newline> is ignored, and \ must be used to quote the characters \,
       $, and ‘.

Also einfach:
Code:
cat << 'EOF' > ergebnis
[ "$UID" = "0" ] || su -
EOF
 

Ähnliche Themen

Keine grafische Oberfläche (Debian Installation)

SELinux und IPTV

X11 Monitor Position

SED und TCPDUMP

Raspbian: Starten einer Java-GUI Anwendung beim Systemstart (JBidWatcher)

Zurück
Oben