help-bash
[Top][All Lists]
Advanced

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

Re: Why is -- in the output of declare -p x?


From: Koichi Murase
Subject: Re: Why is -- in the output of declare -p x?
Date: Wed, 25 Jan 2023 21:52:24 +0900

2023年1月25日(水) 7:22 Peng Yu <pengyu.ut@gmail.com>:
> I see -- in the output of declare -p x. Why is it necessary to keep it
> there? Is it better to remove it for brevity? Thanks.

There can be different kinds of uses for the output of `declare -p'.
An obvious one is for humans to check the state of the variable, for
which brevity could be useful. Another one is to serialize the state
of the variable into a string for later `eval's, for which brevity is
mostly irrelevant (except that it might reduce the size a bit). Even
another one is for external programs or shell scripts to read the
state of the variable, for which consistency wins over brevity.

I don't know what is the original intent of this behavior, but it
would be useful to always have the variable assignment as the third
word when one wants to manipulate the output of `declare -p' in a
program. Otherwise, the program needs to make a test against the value
of the second word to judge which word it should pick.



reply via email to

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