News for hackers. Stuff that matters.
Re:Escaping strings in Bash using !:q by Tepix on Friday October 02, 2020 @03:04AM (#24659808)
Even better, put this in your ~/.bashrc

    function bashquote () {
        printf '%q' "$(cat)"
        echo
    }
Re:Escaping strings in Bash using !:q by asicsp on Friday October 02, 2020 @04:30AM (#24660392)
Golfed one-liner

    bashquote() { printf '%q\n' "$(cat)" ; }
Re:Escaping strings in Bash using !:q by KMnO4 on Friday October 02, 2020 @07:25AM (#24661458)
You should contact your administrator if you are still paying per-line for your .bashrc
Re:Escaping strings in Bash using !:q by dotancohen on Friday October 02, 2020 @08:22AM (#24661861)
I think he's just saving on keystokes because those Model M's are getting hard to find.
Re:Escaping strings in Bash using !:q by Tepix on Friday October 02, 2020 @02:40PM (#24665653)
Can't we get rid of cat somehow?
Re:Escaping strings in Bash using !:q by kps on Friday October 02, 2020 @11:07PM (#24669168)
Yes,

    bashquote() { printf '%q\n' "$(</dev/stdin)"; }
Bash treats the string "/dev/stdin" as magic, so that works even if /dev/stdin doesn't exist. However, bash (unlike ksh) spawns a subshell for $(</dev/stdin), so using cat is actually lighter. (Also, it's not clear to me why $(<&0) doesn't work in bash.)