I'm using Bash on both client and server. When running a command over SSH:
-
ssh <host> 'declare'
gives a list of shell variables. -
ssh <host> 'mount'
gives a list of mountpoints.
However, declare
is a Bash builtin, while mount
is an external command. How does SSH know which to run if there is a shell builtin and an external command with the same name on the server?
Best Answer
The
ssh
runs the commands you provide in the remote user's shell (obtained from the/etc/passwd
), as visible from the source code:Therefore the respective commands that is executed for your example on the remote server are:
bash -c declare
bash -c mount
Both of them are passed to the
bash
and evaluated. Built-ins are evaluated inside, and the external commands are called as if you would do that from your local command line prompt.