News for hackers. Stuff that matters.
Re:Escaping strings in Bash using !:q by bhpnpmg on Friday October 02, 2020 @07:05PM (#24667929)
I wrote bash function that leverages 'set -x' to get me the quoting in "$@" into a single bash env var say $job or in to a temp file. I use it from time to time -- pretty sure it's not perfect, but it works well enough to be useful. To use it it usually involves an 'eval'.
Re:Escaping strings in Bash using !:q by bhpnpmg on Friday October 02, 2020 @07:10PM (#24667961)
## key step: out=$((set -o xtrace;: "$@") 2>&1) # xtrace option shows us quoting for our args

    ## Cleanup $out
    #  only 1 of the next 4 'left trims' is expected to change $out:
    out=${out#+++++ }
      # if $FUNCNAME is eval'd three times there are five "+" chars
    out=${out#++++ }
      # if $FUNCNAME is eval'd twice there are four "+" chars
    out=${out#+++ }
      # if $FUNCNAME is eval'd there are three "+" chars
    out=${out#++ }
      # xtrace prepends the '++ '; ': ' is from our code shown above.
      # We strip these 5 left most chars.

    # Would be nice to support any level of evals, (hence any no.
    # of '+' chars) [...]