[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Is it really necessary to allow operators and whole right hand sides to
From: |
Peng Yu |
Subject: |
Is it really necessary to allow operators and whole right hand sides to be substituted in (())? |
Date: |
Mon, 17 May 2021 16:07:49 -0500 |
Hi,
$ plus=+; ((x = 1 $plus 2)); declare -p x
declare -x x="3"
I see that the above code works. I think that allowing operators to be
substituted is counterintuitive. If people really want to substitute
operators, it can be done with eval.
$ plus=+; eval "((x = 1 $plus 2))"; declare -p x
declare -x x="3"
Substituting operands is reasonable.
$ x=1; y=2; ((z=$x + $y)); declare -p z
declare -- z="3"
Substituting the how expression seems to be unnecessary and can be
done with eval as well.
$ x='1+2'; ((z=$x)); declare -p z
declare -- z="3"
If I just read `((z=$x))` without knowing its context, it looks like
just a regular assignment, I would not expect that there is
computation going on within `$x`. In this sense, this syntax can allow
unreadable code.
So it would be better not to allow it when this syntax first appeared?
Is there an irrefutable reason that this syntax must have been like
this when it was first introduced? Thanks.
--
Regards,
Peng
- Is it really necessary to allow operators and whole right hand sides to be substituted in (())?,
Peng Yu <=