help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to test if a variable is declared?


From: Alex fxmbsw7 Ratchev
Subject: Re: How to test if a variable is declared?
Date: Sun, 13 Mar 2022 16:01:25 +0100

[[ -v var ]] || printf not\\n

On Sun, Mar 13, 2022, 15:39 Peng Yu <pengyu.ut@gmail.com> wrote:

> Hi Chet, Is adding a switch -q to `declare` to suppress the output of
> `declare -p` or adding a switch to [[ be an option to allow testing
> whether a variable declare?
>
> On 3/13/20, Peng Yu <pengyu.ut@gmail.com> wrote:
> > On Fri, Mar 13, 2020 at 9:25 AM John McKown <
> john.archie.mckown@gmail.com>
> > wrote:
> >
> >> On Fri, Mar 13, 2020 at 9:01 AM Peng Yu <pengyu.ut@gmail.com> wrote:
> >>
> >>> I am trying to use bash efficiently. I am not saying that I have seen
> >>> CPU
> >>> as a concern in a real application. But I want to avoid the
> >>> do-something-then-discard-it approach as much as possible. Sometimes, a
> >>> solution can be found in bash. Sometimes, it can’t be done as in this
> >>> case
> >>> at this moment. Either way is fine with me. But I need to know where
> the
> >>> limit is of bash.
> >>>
> >>> For this specific case, I don’t think that bash could not support it.
> >>> After
> >>> all, it could be supported for example by adding a new switch to [[.
> >>>
> >>
> >> Or maybe a "-q" (for quiet) or "-s" (for silent) as a "suboption" for
> >> declare -p (declare -pq variable) so that it only sets $?
> >>
> >
> > That also could be a possibility.
> >
> >
> >>
> >>
> >>>
> >>>
> >>> Peng
> >>
> >>
> >>>
> >>
> >> --
> >> People in sleeping bags are the soft tacos of the bear world.
> >> Maranatha! <><
> >> John McKown
> >>
> > --
> > Regards,
> > Peng
> >
>
>
> --
> Regards,
> Peng
>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]