|
From: | L A Walsh |
Subject: | Re: consistency probs var & function re-use |
Date: | Sun, 11 Jun 2017 15:31:37 -0700 |
User-agent: | Thunderbird |
Chet Ramey wrote:
You are misunderstanding what that is supposed to do, or ignoring it. `declare -p' quotes its output in a way that allows it to be reused as shell input. Executing the output of `declare -p' will recreate the variable with an identical value.
Re-use as shell input? That's a bit vague. As the right-hand expression for an assignment? or something one reads in? There are plenty of examples that could qualify as being "shell input" that don't work: exec of output: > x=$'foo\nbar' > exec $(declare -p x) bash: exec: declare: not found Assign & exec w/ quotes: > a=$(declare -p x) > exec "$a" bash: exec: declare -- x="foo bar": not found Assign&exec w/o quotes: > exec $a bash: exec: declare: not found Assign & try direct interpretation of value: > $a bash: declare: `bar"': not a valid identifier Same w/quoteS: > "$a" bash: $'declare -- x="foo\nbar"': command not found Reading output: > declare -p x|while read def; do > echo "def=$def" > done def=declare -- x="foo def=bar" Reading it via proc-subst: > read a< <(declare -p x) Ishtar:law> echo "$a" declare -- x="foo (I'm running out of ideas)... It's not very easy to discern what you mean. I'm sure it is easy for someone who already knows the answer -- trivial even, but what type of bash-input are you referring to?
[Prev in Thread] | Current Thread | [Next in Thread] |