[Top][All Lists]

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

Re: is it a bug that \e's dont get escaped in declare -p output

From: Léa Gris
Subject: Re: is it a bug that \e's dont get escaped in declare -p output
Date: Wed, 17 Mar 2021 21:59:01 +0100
User-agent: Telnet/1.0 [tlh] (PDP11/DEC)

Le 17/03/2021 à 21:13, Alex fxmbsw7 Ratchev écrivait :
hm at least now we know array declare -p formatting would work in
workarounds, good to .. :)

Instead of:

var=$'1\e[G\e[K2' ; declare -p var


var=$'1\e[G\e[K2' ; printf 'declare -- %s\n' "${var@A}"

And if you want a human readable dumpvars, then code it.

Here it is:

#!/usr/bin/env bash

dump_vars () {
  local ___varname
  for ___varname; do
    local ___varflags=${!___varname@a}
    if [[ "$___varflags" =~ [Aa] ]]; then
      declare -p "$___varname"
printf 'declare -%s %s=%q\n' "$___varflags" "$___varname" "${!___varname}"

escapearray=($'new \n line' $'and \e esc')
declare -A assocarray=([$'1\e[G\e[K2']=$'and \e esc' [$'new \n line']=$'1\e[G\e[K2')
declare -i intvar=42
declare -ai intarray=(-42 666 555)
declare -Ai intassoc=([foo]=123 [$'1\e[G\e[K2']=456 [bar]=789)

dump_vars escapestring escapearray assocarray intvar intarray intassoc


declare -- escapestring=$'1\E[G\E[K2'
declare -a escapearray=([0]=$'new \n line' [1]=$'and \E esc')
declare -A assocarray=([$'1\E[G\E[K2']=$'and \E esc' [$'new \n 
line']=$'1\E[G\E[K2' )
declare -i intvar=42
declare -ai intarray=([0]="-42" [1]="666" [2]="555")
declare -Ai intassoc=([$'1\E[G\E[K2']="456" [foo]="123" [bar]="789" )
declare -i nameref=42

Léa Gris

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

reply via email to

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