Suppose you have a variable whose value contains bash-escapes and quotes, and
you need to perform the operations bash would perform on that string to turn it
into a literal word.
var=“foo\ bar/“
How would you proceed to get the literal “foo bar/“ out of that, in a safe way
(ie. perform just pathname expansion and quote removal, maybe even word
splitting but that taking into account the quoted whitespace)? Specifically, I
do NOT want any risk of performing command execution or any other expansions on
the data (eg. “foo $(rm -rf ~)/“ should not run rm, “foo\ */“ should not expand
*/, etc.). Essentially, I just want to turn a bash word into a literal.
I need this, because I’m trying to write a safe programmable completion
function and I need to be able to test the word that’s being completed (eg.
foo\ ba) against the possible literals that can be completed (eg. foo bar/).
It seems like everyone who’s writing a programmable completion function needs
this facility yet it appears to be lacking in bash. If I haven’t overlooked
the solution, it appears a glaring issue which might be at the root of all bash
completion functions being so buggy, and I should probably continue this topic
on bug-bash.
— Maarten Billemont (lhunath) —
me: http://www.lhunath.com – business: http://www.lyndir.com –
http://masterpasswordapp.com
signature.asc Description: Message signed with OpenPGP using GPGMail