help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] Performing quote removal on data


From: Maarten Billemont
Subject: [Help-bash] Performing quote removal on data
Date: Wed, 28 May 2014 00:44:20 -0400

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.comhttp://masterpasswordapp.com

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail


reply via email to

[Prev in Thread] Current Thread [Next in Thread]