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: Peng Yu
Subject: Re: How to test if a variable is declared?
Date: Fri, 13 Mar 2020 09:00:18 -0500

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 [[.

On Fri, Mar 13, 2020 at 8:21 AM Pier Paolo Grassi <address@hidden>
wrote:

> Hi Peng, from your focus on reducing cpu usage it seems to me you are
> trying to do something for which bash maybe isn't the right tool
> Hence some frustration can arise from your very specific but apparently
> unmotivated needs
> maybe you can try explaining what you are trying to achieve and the
> constraint that you have, and ask for the list opinion on whether this is
> achievable or not
>
>
> Il giorno ven 13 mar 2020 alle ore 14:16 Peng Yu <address@hidden> ha
> scritto:
>
>> I also said along the line of [[. I probably should make it more clear
>> that
>> I just want to test if a variable is declared but not anything else.
>>
>> On Fri, Mar 13, 2020 at 8:11 AM Eli Schwartz <address@hidden>
>> wrote:
>>
>> > On 3/13/20 8:55 AM, Peng Yu wrote:
>> > > This still prints. It just got redirected to null. So when the
>> variable
>> > > contains a long string, it will use extra CPU for a test that could be
>> > made
>> > > more light weight. So there is no way to just test if a variable is
>> > > declared in bash?
>> >
>> > Is "no, there isn't" an acceptable answer?
>> >
>> > The closest you will get is printing it out to null, and testing the
>> > return status of that print.
>> >
>> > P.S. If your initial response is "I don't want it to print to the
>> > screen", and then when someone shows you how to not print to the screen
>> > and you change your mind and say "I don't want it to print at all", it
>> > gets rather frustrating. Maybe it would be beneficial if you list your
>> > conditions from the start, rather than waiting for people to give you
>> > answers you don't like?
>> >
>> > --
>> > Eli Schwartz
>> > Arch Linux Bug Wrangler and Trusted User
>> >
>> > --
>> Regards,
>> Peng
>>
> --
Regards,
Peng


reply via email to

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