Ich bin ein Problem unter Befehl ausführen bekommen:Shell-Funktion Problem - den Apostroph aus der Shell-Anweisung
wenn ich laufe: cmssh 12np, ich meinte die definierte Funktion cmssh aufzurufen, schließlich ich einen Shell-Befehl erwarte Zeile wie folgt aus:
sshpass -p password ssh mydomain\\[email protected]
, unter Quelle sehen:
alias 12np='ssh mydomain\\[email protected]@host.com'
function cmssh() {
set -x
local aliascmd=$1
cmdstr=$(alias $aliascmd | cut -d'=' -f2 | cut -d"'" -f2)
echo $cmdstr
sshpass -p "$cmpw" $cmdstr
#debug cmdstr : sshpass -p password 'ssh mydomain\\[email protected]'
}
der letzte Schritt immer machen jedoch das Ergebnis als:
sshpass -p password 'ssh mydomain\\[email protected]'
Ich habe versucht viele Möglichkeiten zu versuchen, das einfache Zitat zu entfernen, aber habe keine Ahnung, wie es möglich ist.
Siehe die Debug-Informationen:
~ cmssh 12np
+cmssh:2> local 'aliascmd=12np'
+cmssh:4> cmdstr=+cmssh:4> alias 12np
+cmssh:4> cmdstr=+cmssh:4> cmdstr=+cmssh:4> cut '-d=' -f2
+cmssh:4> cut '-d'\' -f2
+cmssh:4> cmdstr='ssh mydomain\\[email protected]'
+cmssh:7> echo 'ssh mydomain\\[email protected]'
ssh mydomain\\[email protected]
+cmssh:8> sshpass -p password 'ssh mydomain\\[email protected]'
sshpass: Failed to run command: No such file or directory
Dank
Gibt es Sonderzeichen in Ihrem Passwort? Wenn Sie Ihr Passwort in '$ cmpw' speichern und' sshpass -p "$ cmpw" ssh mydomain \\ userxyz @ host.com' in der Befehlszeile ausführen, wird es dann erfolgreich ausgeführt? –
Welche Shell führt das aus? Sieht aus wie 'Bash', aber bitte bestätigen. – mklement0