Problem beim Escapen von Sonderzeichen

T

trequ1

Grünschnabel
Hallo.

Ich möchte eine Datei über einen rsh Tunnel ändern.

Der Tunnel funktioniert bei mir wie folgt:
Code:
echo '[Befehl] 2>&1; echo ==ERROR== $?' | /usr/bin/remsh [HOST] -l [USER] /bin/sh -

Der Befehl "hostname" gibt z.B.
rechnername.domain ==ERROR== 0
zurück.
Damit kann ich dann auch den Remote-Exit Code ermitteln und mit $? den lokalen rsh exit-code ermitteln

Ich müsste jetzt den folgenden Befehl ausführen:
Code:
awk '{print $0} /^Line 2/ {print "Test"}' < /etc/passwd > /etc/passwd_new

Mein Problem ist jetzt, dass ich das ganze nicht auskommentiert bekomme.

Beispiel:
Code:
echo "awk {print \$0} /^Line 2/ {print 'Test'} < testfile"
awk {print \-tcsh} /^Line 2/ {print 'Test'} < testfile
 
Bei deinem Beispiel fehlen die Quotes um das awk Script (außerdem wird $0 expandiert trotz escape, in (ba)sh wäre das einfacher..)

Hier mal 2 Varianten, die in (ba|k)?sh funktionieren:
Code:
echo 'awk '\''{print $0} /^Line 2/ {print "Test"}'\'' < testfile'
echo 'awk '"'"'{print $0} /^Line 2/ {print "Test"}'"'"' < testfile'
Varianten mit double quotes um den awk Befehl hab ich mal bewusst weggelassen, da die tcsh ja scheinbar sonst $0 expandiert (trotz backslash)..

Wenn die tcsh das anbietet, möchtest du vielleicht lieber auf ein here doc zurückgreifen:
Code:
cat << 'EOF' > command.file
echo this is 'a "sample" command' "with lot's of quotes" and unexpanded variabbles, like '$foo' '$bar' '$0'
EOF

bash < command.file

Output:
Code:
this is a "sample" command with lot's of quotes and unexpanded variabbles, like $foo $bar $0
Das ist imho die "sauberste" Methode. Denn hier ist jedwede shell Interaktion mit deinem code unterdrückt. (Man beachte die single-quotes um 'EOF')
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.  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.  If word is unquoted, all lines of the here-docu‐
       ment are subjected to parameter expansion, command substitution, and arithmetic expansion.  In the lat‐
       ter  case,  the character sequence \<newline> is ignored, and \ must be used to quote the characters \,
       $, and ‘.
(aus "man bash", musst halt schauen, ob tcsh sowas auch hat..)
 

Ähnliche Themen

ip6tables Problem

Shellskript - Fehler in Cron

verzeichniss suche funktioniert nicht

KSH: Problem beim Umleiten des Fehlerkanals

Problem mit HSPA+ Modem Huawei E353 - Installation unmöglich?

Zurück
Oben