0

From help declare:

-p        display the attributes and value of each NAME

Just running declare -p works as expected. So does running it in a subshell with (declare -p).

However, when using echo "$(declare -p)", i.e. executing the command in a subshell, catching stdout and echoing that to stdout again, I noticed something weird happening: With each call, the output of declare -p gets longer and additional backslashes appear. The execution also takes increasingly longer.

Output of first run of echo "$(declare -p)":

...
declare -x SHELL="/bin/bash"
...

Second run:

...
declare -x SHELL="/bin/bash"
...
declare -x SHELL=\"/bin/bash\"
...

Third run:

...
declare -x SHELL="/bin/bash"
...
declare -x SHELL=\"/bin/bash\"
...
declare -x SHELL=\\\"/bin/bash\\\"
...

What's going on here?

2
  • 3
    As you're doing this, take note of the first line starting with declare -- _=" -- gnu.org/software/bash/manual/bash.html#index-_005f Commented Oct 14, 2022 at 18:46
  • @glennjackman Ohhh so I'm simply seeing the very long content of the _ variable! I would've never thought of that. Thank you very much for your help :) Commented Oct 14, 2022 at 21:45

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.