3 ms·
A nice collection of issues, although I'd disagree a bit with some of the solutions, particularly around prefixing. You first need to check if you have an abso
by joveian 3y ago
A nice collection of issues, although I'd disagree a bit with some of the solutions, particularly around prefixing. You first need to check if you have an absolute path and it doesn't work with input that isn't a path. So for me it seems best to focus on -- as the primary measure and prefixing as an additional measure if possible when needing to be extra careful. Most software uses some getopt variant so it should be quite rare that -- doesn't work.
One nice thing about bash is the ${var@Q} syntax that is great for printing stuff and deals with the potential for stuff that affects the terminal in a much nicer way than piping through tr. IMO, it should always be used for pathnames so that you can always just copy and paste the output, which I do quite a bit. I wish it was in POSIX.
- Calzifer 3y ago> One nice thing about bash is the ${var@Q} syntax that is great for printing stuff and deals with the potential for stuff that affects the terminal in a much nicer way than piping through tr. An alternative which works in both Bash and Zsh is printf %q "$var" using /usr/bin/printf %q "$var" has even a good chance to work in other shells. And as fun fact: the Zsh equivalent for Bash's ${var@@} is ${(q)var} and it was not enough to have one quoting style but instead you can also provide qq, qqq, qqqq, q+ or q- all with a different result. https://zsh.sourceforge.io/Doc/Release/Expansion.html#Parameter-Expansion-Flags https://zsh.sourceforge.io/Doc/Release/Expansion.html#Parame...