bug-bash
[Top][All Lists]
Advanced

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

q// / qq// syntax or built-ins please ?


From: Jason Vas Dias
Subject: q// / qq// syntax or built-ins please ?
Date: Thu, 23 Mar 2017 20:40:35 +0000

Please , in some future versions of bash, could it provide
support / help for avoiding "quoting hell", in such situations
as :

$ echo "

Error: Cannot find file '/missing/file_1'.

Error: Cannot find file '/missing/file_2'.

"  |  while read line; do
   cmd='if [[ '$'"'"$line"$'"'' =~
^[^'"\\'"']*['"\\'"']([^'"\\'"']+)['"\\'"'][^'"\\'"']*$ ]]; then echo
${BASH_REMATCH[1]}; fi;';
  echo "$cmd" | bash -;
done

See what I have to do to match lines containing a non-empty
single-quoted string ?
ie. I just want to cut-and-paste such lines from the output of some
application, and
weed out the empty lines and print the  single-quoted string in lines
containing them (only!), with a simple bash command. If you replace
"echo $cmd | bash -" with
'eval "$cmd"' , it does not work, because the double-quotes which I
had painstakingly inserted with '$'"''  get removed somehow by eval -
why is this?
ie, only if "$line" is empty, does bash evaluate the text:
   'if [[ "" = ... ]]; then ...'
else, for the lines I want to match, it would evaluate eg. :
+ eval 'if [[ Error: Cannot find file '\''/missing_file_1'\''.\" =~
^[^\\\'\'']*[\\\'\'']([\\\'\'']+)[\\\'\''][^\\\'\'']*$ ]]; then echo
${BASH_REMATCH[1]}; fi;'
+ set +x
( nothing printed - the single quotes are stripped)
+ eval 'if [[ \"\" =~
^[^\\\'\'']*[\\\'\'']([\\\'\'']+)[\\\'\''][^\\\'\'']*$ ]]; then echo
${BASH_REMATCH[1]}; fi;'
++ [[ "" =~ ^[^\']*[\']([\']+)[\'][^\']*$ ]]
+ set +x
+

I think bash needs some kind of "q/.../'" and 'qq/../' syntax / built-ins, or
whatever syntax its author likes,  like PERL has, whereby the  single quote
("'") or double quote ('"') respectively are totally ignored within
'/.../'  parameter
strings, which should use a different quoting character than '"' or
"'" to delineate
them.

If the author won't develop these, I will & will send a patch.

Regards,
Jason



reply via email to

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