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.

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.

  • 9
    And also don't enable nullglob which would have it expand to empty string – Eric Renouf Sep 7 '15 at 15:25
  • 1
    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 Sep 8 '15 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.