[vox-tech] shell question: globbing and command arguments

ME vox-tech@lists.lugod.org
Mon, 3 Nov 2003 09:05:29 -0800 (PST)


p@dirac.org said:
> if i have a bunch of files on a remote host beginning with "backup", i
> can copy them to the local host using:
>
>    scp p@remote.host:backup* .
>
> and it works.  but why?

Assuming you are using bash, and you have files on your local machine that
start with "backup" I think the scp will complete the files based on the
named in your local directory.

If the local directory was empty, and then you tried the above like this:
$ scp p@remote.host:backup* .
The results would not like be the same as when you found them to work.
(They only "work" because of the files in your local dir.)

To use the "*" on remote machines, try escaping it:
$ scp p@remote.host:backup\* .
(This should work even when you do it from a locally empy dir.)

This works. On the remote machine, the * is applied as a wild card.

> doesn't the shell get to "*" first?

It should, and I expect it to fail if you do not have files in the local
machine's dir that start with "backup"

> i'd understand this working:
>
>    scp 'p@remote.host:backup*' .
>
> but why does scp see the asterisk in the unquoted version?

(guesses above)

HTH,
-ME