[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Why is -- in the output of declare -p x?
From: |
Peng Yu |
Subject: |
Re: Why is -- in the output of declare -p x? |
Date: |
Wed, 25 Jan 2023 11:06:15 -0600 |
help says `-p display the attributes and value of each NAME`. I'd
assume at least one purpose is for human to read. If so, then it is
better to remove the unnecessary -- whenever possible.
After all, the program which uses -p has control to what variable
names should be used. It can choose variable names such that -- is
never needed, in such case, those programs never need to test whether
there is -- or not.
On 1/25/23, Koichi Murase <myoga.murase@gmail.com> wrote:
> 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.
>
--
Regards,
Peng
- Why is -- in the output of declare -p x?, Peng Yu, 2023/01/24
- Re: Why is -- in the output of declare -p x?, Koichi Murase, 2023/01/25
- Re: Why is -- in the output of declare -p x?,
Peng Yu <=
- Re: Why is -- in the output of declare -p x?, Kerin Millar, 2023/01/25
- Re: Why is -- in the output of declare -p x?, Lawrence Velázquez, 2023/01/25
- Re: Why is -- in the output of declare -p x?, Peng Yu, 2023/01/26
- Re: Why is -- in the output of declare -p x?, Lawrence Velázquez, 2023/01/26
- Re: Why is -- in the output of declare -p x?, Peng Yu, 2023/01/26
- Re: Why is -- in the output of declare -p x?, Kerin Millar, 2023/01/26
- Re: Why is -- in the output of declare -p x?, alex xmb ratchev, 2023/01/25