[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Conditional operator in Shell Arithmetic section
From: |
uzibalqa |
Subject: |
Re: Conditional operator in Shell Arithmetic section |
Date: |
Sat, 18 Mar 2023 20:30:05 +0000 |
------- Original Message -------
On Sunday, March 19th, 2023 at 7:41 AM, Lawrence Velázquez <vq@larryv.me> wrote:
> 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.
This is how it is described in the Awk Manual
selector ? if-true-exp : if-false-exp
Which is much more informative.
> > 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.
There is need if you actually want to help readers. The awk maintainers
certainly understood the need for an actual use case (getting the absolute
value of x).
> > 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.
If you look at the Awk Manual, some maintainers are surely convinced that in
belrongs in "6.3.4 Conditional Expressions".
> > 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.
Would appreciate ways that are more likely to locate it. It is widely known
under the term Ternary Conditional often indexed with ?:
So I could not search with that. It would be good to include.
> --
> 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, 2023/03/18
- Re: Conditional operator in Shell Arithmetic section,
uzibalqa <=
- 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