[Top][All Lists]

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

Control characters in declare output

From: Rob Foehl
Subject: Control characters in declare output
Date: Thu, 1 Nov 2018 02:01:07 -0400 (EDT)

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. 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.


╶➤ y=$'\e[31m'"oops"$'\e[0m'

╶➤ declare -p y
declare -- y="oops"

String again in red.  Compare with:

╶➤ set |grep ^y=

No issues with the set output. As they can both be usefully re-read by the shell, is there any possibility for similarly escaped output from the declare builtin, instead of raw control characters?


reply via email to

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