I have a local and a remote host, both running Ubuntu, with the shell set to bash. In my home directory, I have two files, file-1
and file-2
, both on the local host, and on a remote host called remote
. There are some other files in each home directory, and I want to list only files matching file-*
.
Locally, these produce the expected result, file-1 file-2
:
$ ls file-*
$ bash -c 'ls file-*'
But these commands return ALL files in my home directory on the remote. What's going on there?
$ ssh remote bash -c 'ls file-*'
$ ssh remote bash -c 'ls "file-*"'
$ ssh remote bash -c 'ls file-\*'
$ ssh remote bash -c 'ls "file-\*"'
I know that simply ssh remote 'ls file-*'
produces the expected result, but why does ssh remote bash -c 'ls ...'
seem to drop the arguments passed to ls ...
? (I've also piped the output from the remotely executed ls, and it's passed along, so only the ls
seems to be affected: ssh remote bash -c 'ls file-* | xargs -I {} echo "Got this: {}"'
.)
ssh remote bash -c 'ls file-* | xargs -I {} echo "Got this: {}"'
? I had to runssh remote bash -c ':; ls file-* | xargs -I {} echo "Got this: {}"'
(orssh remote bash -c ': && ls file-*'
) to get the expected result – nohillside Jun 01 '20 at 09:47