Why are the arguments supplied for the command run through ssh interpreted by shell before they are passed to the command on the server side?
Thorsten Glaser
t.glaser at tarent.de
Sun Jan 12 03:57:56 AEDT 2020
On Sat, 11 Jan 2020, Yuri wrote:
> It's not obvious why does it have to be this way. ssh sends the command as an
> array of strings. The first string is the command, and the subsequent strings
It doesn’t.
This works:
94 ssh root@$hostbase "
95 PS4='(${hostbase%%.*})++++ '
96 set -ex
97 psql -U veraweb -h 127.0.0.1 veraweb
98 rm -rf /var/lib/tomcat$tomcat/webapps/veraweb
99 rm -rf /var/lib/tomcat$tomcat/webapps/vwor
100 " <core/src/main/files/upgrade.sql
Here, $hostbase and $tomcat are expanded locally. Full code:
https://evolvis.org/plugins/scmgit/cgi-bin/gitweb.cgi?p=veraweb/veraweb.git;a=blob;f=upload.sh;h=b8b0cf92ad36dbc929afd86effe44d9bec888344;hb=HEAD
If you wish for no local expansion, quote locally, such as:
ssh -l luser remotehost '
command1
command2
…
'
Quote any ‘'’ inside as “'\''”, that’s it. (Easily done, for
example in AT&T ksh93/GNU bash/mksh: ${cmd//\'/\'\\\'\'})
bye,
//mirabilos
--
tarent solutions GmbH
Rochusstraße 2-4, D-53123 Bonn • http://www.tarent.de/
Tel: +49 228 54881-393 • Fax: +49 228 54881-235
HRB 5168 (AG Bonn) • USt-ID (VAT): DE122264941
Geschäftsführer: Dr. Stefan Barth, Kai Ebenrett, Boris Esser, Alexander Steeg
More information about the openssh-unix-dev
mailing list