24

I'm typing this in Bash:

scp user@remote:~/dir/*.xml .

and it works, getting all the files that make the wildcard on the remote server. But why does this work? I thought that Bash expands wildcard expressions in arguments before the arguments become visible to a tool like scp.

1 Answer 1

31

If there is no matching filename, then a wildcard expression in bash expands to itself. So, as long as you don't create any file locally whose name matches user@remote:~/dir/*.xml, your command works without quoting.

2
  • 9
    And also don't enable nullglob which would have it expand to empty string Commented Sep 7, 2015 at 15:25
  • 2
    nullglob doesn't cause the pattern to expand to the empty string; it causes it to disappear altogether. It's the difference between scp "" . (two arguments, one of which is the empty string) and scp . (a single argument and an invalid call to scp).
    – chepner
    Commented Sep 8, 2015 at 14:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .