Can files be created with "-" in Unix? I am using a Linux system and I am not able to do so using vim or touch commands.
Unix Wildcards Gone Wild
41–50 of 54 posts
Re: Unix Wildcards Gone Wild
#42This is a dumb question. Can files be created with "-" in Unix? I am using a Linux system and I am not able to do so using vim or touch commands.
touch -- -asdf
Re: Unix Wildcards Gone Wild
#43Re: Unix Wildcards Gone Wild
#44Re: Unix Wildcards Gone Wild
#45This is a dumb question. Can files be created with "-" in Unix? I am using a Linux system and I am not able to do so using vim or touch commands.
Re: Unix Wildcards Gone Wild
#46Tangentially, 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.
There's also `noglob`, which disables glob expansion for a command (e.g. `noglob echo 3*4 | bc`).
Re: Unix Wildcards Gone Wild
#47Tangentially, 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.
IIRC zsh has an option for this (if a wildcard has no matches, it just gets left in its original form), but I don't remember what. There's also `noglob`, which disables glob expansion for a command (e.g. `noglob echo 3*4 | bc`).
Re: Unix Wildcards Gone Wild
#48For example chown username:username files directory -R
Doesn't actually work. You have to move the -R to before the usernames. chown -R username:username files directory.
Same thing with rm.
Re: Unix Wildcards Gone Wild
#49David 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…
> portably in shell scripts (spoiler: it's hard ) At what point do you give up and, if you must have portability, bootstrap a saner environment? Are there many options in this area? Assume perl is available? Use autoconf-like shell script compiler? Starting with Lua (which I hope/assume can build anywhere, though I know it's missing lots of functionality out of the box)?
Not embedded devices, but I guess those are different enough that you're probably not targetting them for portable scripts. Oh no, have I contradicted myself? :)
Re: Unix Wildcards Gone Wild
#50Many 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... .
The reasons given there aren’t really any good: 1. For “--” to work, all maintainers would have to faithfully use “--” in practically every command invocation. That just doesn’t happen in real life, even after decades of people trying. People forget it all the time; no one is that consistent, especially since code seems to work without it. Very few commands require it, after all. So because other people may or may no…
He specifically mentions that that is not his point, but rather that he is arguing against exactly the sort of "just use '--'" response that one can find in this post:
> Do feel free to use “--” between options and pathnames, when you can do it, as an additional protective measure. But using “--” as your primary (or only) mechanism for dash-prefixed filenames is bad idea.