Live data from Hacker News

Unix Wildcards Gone Wild

defensecode.com

11–20 of 54 posts

Re: Unix Wildcards Gone Wild

#11
Many people are recommending the '--' option-terminating option. Note David Wheeler's caution (in the essay already linked by AceJohnny2 at https://news.ycombinator.com/item?id=8190208) about why this is not an all-purpose solution: http://www.dwheeler.com/essays/filenames-in-shell.html#dashd....

Re: Unix Wildcards Gone Wild

#12

David A. Wheeler, FOSS (and occasionally security) luminary, who also happens to be creator of the popular sloccount tool, has an excellent page that covers this topic and how to use paths safely and portably in shell scripts (spoiler: it's hard ) : http://www.dwheeler.com/essays/filenames-in-shell.html I strongly recommend his many other essays to HN readers: http://www.dwheeler.com/ Edit: a simple way to avoid thes…

The double dash -- to stop option parsing is not a GNU thing – it comes from the POSIX standard.

Re: Unix Wildcards Gone Wild

#13
post #12

David A. Wheeler, FOSS (and occasionally security) luminary, who also happens to be creator of the popular sloccount tool, has an excellent page that covers this topic and how to use paths safely and portably in shell scripts (spoiler: it's hard ) : http://www.dwheeler.com/essays/filenames-in-shell.html I strongly recommend his many other essays to HN readers: http://www.dwheeler.com/ Edit: a simple way to avoid thes…

The double dash -- to stop option parsing is not a GNU thing – it comes from the POSIX standard.

Thanks! I had always figured that, along with long options, they were a GNU thing.

Re: Unix Wildcards Gone Wild

#14
Tangentially, anyone know how to make zsh less greedy about parsing wildcards? Something like this will fail with "no files matched", and the command won't run:

    rsync example.com:/foo/* .
My workaround is to quote the argument, but it's annoying.

Re: Unix Wildcards Gone Wild

#15

Tangentially, anyone know how to make zsh less greedy about parsing wildcards? Something like this will fail with "no files matched", and the command won't run: rsync example.com:/foo/* . My workaround is to quote the argument, but it's annoying.

How about one of

    rsync -a example.com:/foo/. .
    rsync example.com:/foo/"*" .

Re: Unix Wildcards Gone Wild

#17

Tangentially, anyone know how to make zsh less greedy about parsing wildcards? Something like this will fail with "no files matched", and the command won't run: rsync example.com:/foo/* . My workaround is to quote the argument, but it's annoying.

escape it, since you know the shell is going to be greedy about things.

rsync accepts globbing it's not a shell expansion that makes it work.

     rsync example.com:/foo/\* .

Re: Unix Wildcards Gone Wild

#19

   echo rm *

   echo chown -R nobody:nobody *.php

   echo chmod 000 *

   echo tar cvvf archive.tar *

   echo tar cf archive.tar *

   echo rsync -t *.c foo:src
This article starts with the premise that the person executing the command has no idea what files are in the current working directory. That is itself a more serious problem than the behaviour of wildcards.

Later in the article we learn that it also assumes GNU utilities. That is a second problem (IMO), and arguably also one more serious than the behaviour of wildcards. GNU userland and unneeded complexity (e.g. more features than any user will ever use) are practically synonymous.

Then there is the peculiar assumption that someone can place arbitrary files beginning with - or -- on this system. That itself is a far more serious problem than the behaviour of wildcards; I would say with that capability it is more or less "game over". In BSD you have, at the very least, mtree. How does the Linux user know she isn't executing some substituted executable?

Moreover, if caution was important to the hypothetical user in the examples, I think they would be in the form

   /path/to/program *
Post reply on HN