Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14760 > unrolled thread

Re: Control characters in declare output

Started byChet Ramey <chet.ramey@case.edu>
First post2018-11-01 11:06 -0400
Last post2018-11-01 11:06 -0400
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Control characters in declare output Chet Ramey <chet.ramey@case.edu> - 2018-11-01 11:06 -0400

#14760 — Re: Control characters in declare output

FromChet Ramey <chet.ramey@case.edu>
Date2018-11-01 11:06 -0400
SubjectRe: Control characters in declare output
Message-ID<mailman.3219.1541084837.1284.bug-bash@gnu.org>
On 11/1/18 2:01 AM, Rob Foehl wrote:
> Prompted (pun intended) by the recent thread on detecting missing newlines
> in command output, I'd had another look at my own version, and discovered a
> potential issue with control characters being written as-is in declare
> output.  

I don't see it as much of an issue.

Minimal (harmless) reproducer:
> 
> ╶➤ x () { echo $'\e[31m'"oops"$'\e[0m'; }
> 
> ╶➤ declare -f x
> x ()
> {
>     echo ''"oops"''
> }
> 
> Emits the string in red in a terminal.  Any instances with control
> sequences that do anything more invasive with the terminal cause more trouble.

As documented, $'...' strings are expanded and converted to single-quoted
strings by the parser. In this case, that means while the function
definition is read and parsed, so the actual definition includes raw
control characters. It's difficult to make a good case for escaping these
characters while printing the function definition, which has to print
commands, while printing variable values is much more limited in scope.


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web