3 ms·
$ curl https://dwheeler.com/essays/fixing-unix-linux-filenames.html > /tmp/page.html $ grep -c '"$@"' /tmp/page.html 0 $ grep -c '$@' /tmp/page.htm
by pdkl95 8y ago
$ curl https://dwheeler.com/essays/fixing-unix-linux-filenames.html > /tmp/page.html
$ grep -c '"$@"' /tmp/page.html
0
$ grep -c '$@' /tmp/page.html
0
For some reason this article talks about lots of incorrect metho9ds of handling filenames in Bourne shell, and completely ignores the correct solution that fixes a lot of the problem: always use double quotes, and iterating over "$@".
- dwheeler 8y agoBut that does not solve the problem at all. File names with leading dashes will be interpreted exactly the same way. Displaying a file name may cause terminal escapes to suddenly be executed. A list are file names separated by new lines still fails to work. Indeed I specifically showed many cases even in Shell where using "$@" does not help, and many of the problems hit even if you aren't using a shell at all.
- pdkl95 8y ago> But that does not solve the problem at all. I never claimed it did. I'm commenting on the many Bourne shell examples in the article, which seem to use many common incorrect solutions, while ignoring the method that was added to the shell specifically to fix argument[1] handling, > Displaying a file name may cause terminal escapes to suddenly be executed I'm not addressing program output, because program output always has that type of problem. You can also have the same problem when you display the contents of a file or user input. This gets even harder to solve when Unicode is involved, regardless of encoding, and regardless of source. Again, if you aren't validating and sanitizing your input, you have bigger (probably security related) problems that cannot be solved by changing how the OS handles filenames. > Indeed I specifically showed many cases even in Shell where using "$@" does not help Where? The only @ in the document that I can find is an example using arrays, which is different than the specific string "$@" (those 4 chars only) that is defined as copying the current args (skips word-splitting). From bash(1): >> @ Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. That is, "$@" is equivalent to "$1" "$2" ... [1] The problem of in-band whitespace/etc isn't just a filename issue! Changing how the OS handles filenames doesn't fix non-filename arguments. Again, you're only looking at once small set of problems! edit: typos