On Sat, Mar 18, 2023, at 1:59 PM, uzibalqa wrote:
> Have been reading the manual about the arithmetic conditional operation
> described by
>
> expr ? expr : exp
>
> This is quite difficult to understand exactly how to use it.
I'm sure there are ample C examples out there.
> For instance, consider setting the variable opst to 0 when the length
> of delim in positive in a bash script. One would use
>
> opst=$(( ${#delim} > 0 ? 0 : 1 ))
Or:
if [[ -n $delim ]]; then
opst=0
else
opst=1
fi
or:
[[ -n $delim ]]
opst=$?
or:
opst=$((${#delim} < 1))
or:
opst=$((! ${#delim}))
As Greg said, if you don't understand the operator, don't use it.
You have other options.
> There needs to be at least one example of actual use in a typical
> situation.
No, there doesn't.
> I also suggest to include it in section "3.2.5.2
> Conditional Constructs".
It's already in Section 6.5. It does not belong in 3.2.5.2.
> Specifying conditional operator "expr ? expr : exp" simply as Shell
> Arithmetic makes it very difficult to find in the manual.
The index could be a little more comprehensive, I guess.
--
vq