News for hackers. Stuff that matters.
Re:Safe ways to do things in bash by quietbritishjim on Monday May 14, 2018 @05:30PM (#17069624)
Honest question: what happens when the variable has a quote in it? If FOO is ‹xyz"; rm -r *; "xyz› (where I've used ‹› as delimiters) then won't even "${FOO}" expand to multiple arguments/commands? Or does bash automatically escape the quotes in the situation?
Re:Safe ways to do things in bash by kazinator on Monday May 14, 2018 @07:17PM (#17070272)
Quotes that arise from substitutions aren't considered to be quotes.

Unfortunately, the way GNU Bash handles this sort of requirement is to internally translate these protected quotes into some character that "nobody" would ever use, and then recover them later.

That characters code is none other than ASCII 1 (SOH/Ctrl-A). It's known by the preprocessor symbol CTLESC in the Bash sources.

Re:Safe ways to do things in bash by ben0x539 on Monday May 14, 2018 @08:28PM (#17070640)
jesus christ is nothing sacred
Re:Safe ways to do things in bash by gmjosack on Monday May 14, 2018 @05:46PM (#17069727)
Both of those examples end up being fine. When quoted the entire variable is passed as a single WORD and the shell won't interpret the `;` as the end of the command. Even without quoting the variable it would be fine in this case because of where you've put the quotes, though you should still quote the variables. As a simple illustration take a look at the following:

    function e() {
        echo $#
    }
    $ x="hello world"
    $ e $x
    2
    $ e "$x"
    1