[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Conditional operator in Shell Arithmetic section
From: |
Lawrence Velázquez |
Subject: |
Re: Conditional operator in Shell Arithmetic section |
Date: |
Sat, 18 Mar 2023 15:41:37 -0400 |
User-agent: |
Cyrus-JMAP/3.9.0-alpha0-221-gec32977366-fm-20230306.001-gec329773 |
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
- Conditional operator in Shell Arithmetic section, uzibalqa, 2023/03/18
- Re: Conditional operator in Shell Arithmetic section, Greg Wooledge, 2023/03/18
- Re: Conditional operator in Shell Arithmetic section,
Lawrence Velázquez <=
- Re: Conditional operator in Shell Arithmetic section, uzibalqa, 2023/03/18
- Re: Conditional operator in Shell Arithmetic section, alex xmb ratchev, 2023/03/18
- Re: Conditional operator in Shell Arithmetic section, Lawrence Velázquez, 2023/03/18
- Re: Conditional operator in Shell Arithmetic section, uzibalqa, 2023/03/18
- Re: Conditional operator in Shell Arithmetic section, Lawrence Velázquez, 2023/03/18
- Re: Conditional operator in Shell Arithmetic section, uzibalqa, 2023/03/18
- Re: Conditional operator in Shell Arithmetic section, uzibalqa, 2023/03/19
- Re: Conditional operator in Shell Arithmetic section, Kerin Millar, 2023/03/19
- Re: Conditional operator in Shell Arithmetic section, uzibalqa, 2023/03/19