Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • So ... given the limitation of same shell version, locale, and system, it is meant to be reusable? (Based on comments in the code or mailing list posts or personal discussions or something like that?) Commented Feb 19, 2024 at 10:52
  • @muru well, the doc doesn't say as much, it only appears to be. Commented Feb 19, 2024 at 10:54
  • The linked comment in the source code is about functions, and I have noted in my question that the CHANGES file did document that declare -p is supposed to have reusable output for functions. Commented Feb 19, 2024 at 11:31
  • lists.gnu.org/archive/html/bug-bash/2015-01/msg00017.html is 99% of the way there. So declare -p is "supposed to produce output that can recreate all variables with their attributes", and if the same applies for declare -p name (assuming same shell versions, locale and system and valid variable names) then my question is answered. But that mailing list post also showed one past, but noticeable, difference between the behaviour of declare -p and declare -p name - so one last clarification from me: are there any other major differences between the two wrt variables? Commented Feb 19, 2024 at 14:50
  • If you search the mailing list archives, you'll see it's obviously intended to be valid shell code. The fact that it's not documented as such means that although unlikely it could change in the future. The fact that it has had bugs and is locale-sensitive (uses unsafe forms of quoting) would be other reasons to avoid using it with untrusted data. Commented Feb 19, 2024 at 14:55