Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

You may call me by my name, Wirth, or by my value, Worth. -- Nicklaus Wirth


devel / comp.unix.shell / Re: Unset or empty variable test in (t)csh

SubjectAuthor
* Unset or empty variable test in (t)cshHauke Fath
+* Re: Unset or empty variable test in (t)cshKenny McCormack
|`* Re: Unset or empty variable test in (t)cshHauke Fath
| `- Re: Unset or empty variable test in (t)cshKenny McCormack
`* Re: Unset or empty variable test in (t)cshHauke Fath
 +- Re: Unset or empty variable test in (t)cshKenny McCormack
 `* Re: Unset or empty variable test in (t)cshHauke Fath
  `* Re: Unset or empty variable test in (t)cshKenny McCormack
   `* Re: Unset or empty variable test in (t)cshHauke Fath
    `- Re: Unset or empty variable test in (t)cshKenny McCormack

1
Unset or empty variable test in (t)csh

<1piwk1d.1qnfocmjw81h7N%dont.spam.usenet@googlemail.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4609&group=comp.unix.shell#4609

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: dont.spa...@googlemail.com (Hauke Fath)
Newsgroups: comp.unix.shell
Subject: Unset or empty variable test in (t)csh
Date: Fri, 19 Nov 2021 18:05:34 +0100
Organization: Meistens
Lines: 21
Message-ID: <1piwk1d.1qnfocmjw81h7N%dont.spam.usenet@googlemail.com>
Reply-To: hauke@Espresso.Rhein-Neckar.DE (Hauke Fath)
X-Trace: individual.net sjjFkplN38QIgTY+by4ezQNuVYSi4BEN/fzX//dNQAJa5xqTPD
X-Orig-Path: dont.spam.usenet
Cancel-Lock: sha1:1SyiMCQEuqvn/otSJi28nsjO8e0=
User-Agent: MacSOUP/D-2.8.6b1 (ed136d9b90) (Mac OS 10.13.6)
 by: Hauke Fath - Fri, 19 Nov 2021 17:05 UTC

Hi,

what is the proper {t,}csh way to test if a variable is either unset, or
empty?

The naive

if ( ! ${?TERM} || ${TERM} == "" ) ...

errors out in the second expression, for obvious reasons. While tcsh
does do short circuit expressions, it attempts to expand variables
beforehand.

Cheerio,
Hauke

ObHint: " | sed '/csh.*harmful/d'"

--
Now without signature.

Re: Unset or empty variable test in (t)csh

<sn8mtv$qimb$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4610&group=comp.unix.shell#4610

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Unset or empty variable test in (t)csh
Date: Fri, 19 Nov 2021 17:29:35 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <sn8mtv$qimb$1@news.xmission.com>
References: <1piwk1d.1qnfocmjw81h7N%dont.spam.usenet@googlemail.com>
Injection-Date: Fri, 19 Nov 2021 17:29:35 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="871115"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Fri, 19 Nov 2021 17:29 UTC

In article <1piwk1d.1qnfocmjw81h7N%dont.spam.usenet@googlemail.com>,
Hauke Fath <hauke@Espresso.Rhein-Neckar.DE> wrote:
>Hi,
>
>what is the proper {t,}csh way to test if a variable is either unset, or
>empty?
>
>The naive
>
>if ( ! ${?TERM} || ${TERM} == "" ) ...
>
>errors out in the second expression, for obvious reasons. While tcsh
>does do short circuit expressions, it attempts to expand variables
>beforehand.

You have to do it step by step. For example, the following works for me:

if $?TERM then
if $TERM == "" then
echo "TERM is set but empty"
else
echo "TERM is set to: $TERM"
endif
else
echo "TERM is unset"
endif

>ObHint: " | sed '/csh.*harmful/d'"

Well done!

But, yeah, the syntax of csh/tcsh is kinda creaky, but that's mainly because
it hasn't been maintained (i.e., enhanced, built up, etc) in decades. It
pretty much is what it was in the 1980s. But the fact is, if you use tcsh
as your interactive shell, as I still do, you still need to be able to edit
your startup files and stuff. So, you still need to keeping de old skills
alive!

--
In politics and in life, ignorance is not a virtue.
-- Barack Obama --

Re: Unset or empty variable test in (t)csh

<1piwmwf.1pl1i9s16nqowbN%dont.spam.usenet@googlemail.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4611&group=comp.unix.shell#4611

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: dont.spa...@googlemail.com (Hauke Fath)
Newsgroups: comp.unix.shell
Subject: Re: Unset or empty variable test in (t)csh
Date: Fri, 19 Nov 2021 19:01:16 +0100
Organization: Meistens
Lines: 49
Message-ID: <1piwmwf.1pl1i9s16nqowbN%dont.spam.usenet@googlemail.com>
References: <1piwk1d.1qnfocmjw81h7N%dont.spam.usenet@googlemail.com> <sn8mtv$qimb$1@news.xmission.com>
Reply-To: hauke@Espresso.Rhein-Neckar.DE (Hauke Fath)
X-Trace: individual.net bGASMvbOSXvK5/C785MCrwx826y3L+SKWBh0/+iD7wjx0WYNeW
X-Orig-Path: dont.spam.usenet
Cancel-Lock: sha1:c+cipw4vr971Y+ji79Ly3YzsLXg=
User-Agent: MacSOUP/D-2.8.6b1 (ed136d9b90) (Mac OS 10.13.6)
 by: Hauke Fath - Fri, 19 Nov 2021 18:01 UTC

Kenny McCormack <gazelle@shell.xmission.com> wrote:

> Hauke Fath <hauke@Espresso.Rhein-Neckar.DE> wrote:
> >if ( ! ${?TERM} || ${TERM} == "" ) ...
> >
> >errors out in the second expression, [...]
>
> You have to do it step by step. For example, the following works for me:
>
> if $?TERM then
> if $TERM == "" then
> echo "TERM is set but empty"
> else
> echo "TERM is set to: $TERM"
> endif
> else
> echo "TERM is unset"
> endif

The problem is, this does not give you 'TERM is either unset, or empty'
in one branch.

For the background, the test is from csh.login where I want to run
tset(1) only if TERM is not sane, to avoid side-effects. Since I just
learned that "eval `tset -QIs ...`" will only produce a string, and not
re-initialize the terminal, I am now running tset unconditionally.

> >ObHint: " | sed '/csh.*harmful/d'"
>
> Well done!

From the grab bag of "The [t]csh user's hundred helpful sed one-liners"

[1] ;)

> But, yeah, the syntax of csh/tcsh is kinda creaky, but that's mainly because
> it hasn't been maintained (i.e., enhanced, built up, etc) in decades.

AFAIK csh has a handwritten parser, no defined grammar. Many things are
just as irregular as they are, take 'em or leave 'em.

Cheerio,
Hauke

[1] Also: <https://meyerweb.com/eric/comment/chech.html>

--
Now without signature.

Re: Unset or empty variable test in (t)csh

<1piwodk.rj170lk47a9sN%dont.spam.usenet@googlemail.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4612&group=comp.unix.shell#4612

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: dont.spa...@googlemail.com (Hauke Fath)
Newsgroups: comp.unix.shell
Subject: Re: Unset or empty variable test in (t)csh
Date: Fri, 19 Nov 2021 19:30:21 +0100
Organization: Meistens
Lines: 24
Message-ID: <1piwodk.rj170lk47a9sN%dont.spam.usenet@googlemail.com>
References: <1piwk1d.1qnfocmjw81h7N%dont.spam.usenet@googlemail.com>
Reply-To: hauke@Espresso.Rhein-Neckar.DE (Hauke Fath)
X-Trace: individual.net Sy0PXjNg7gaiWcd//BiWQgx1WJYRqDgW7VcWaFEcPB9wcYRkG9
X-Orig-Path: dont.spam.usenet
Cancel-Lock: sha1:57+8zJNeqhAUQV/IUw9osVaRFAE=
User-Agent: MacSOUP/D-2.8.6b1 (ed136d9b90) (Mac OS 10.13.6)
 by: Hauke Fath - Fri, 19 Nov 2021 18:30 UTC

Hauke Fath <dont.spam.usenet@googlemail.com> wrote:

> The naive
>
> if ( ! ${?TERM} || ${TERM} == "" ) ...
>
> errors out in the second expression

FTR, I just came across [1] whose

if ( ! ${?TERM} || { eval `if ( ${TERM} == "" ) exit 1` } ) ...

fits my bill.

Cheerio,
Hauke

[1]
<https://stackoverflow.com/questions/13343392/how-to-check-if-an-environment-variable-is-either-unset-or-set-to-the-empty-stri>

--
Now without signature.

Re: Unset or empty variable test in (t)csh

<sn8qgg$ql14$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4613&group=comp.unix.shell#4613

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Unset or empty variable test in (t)csh
Date: Fri, 19 Nov 2021 18:30:40 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <sn8qgg$ql14$1@news.xmission.com>
References: <1piwk1d.1qnfocmjw81h7N%dont.spam.usenet@googlemail.com> <sn8mtv$qimb$1@news.xmission.com> <1piwmwf.1pl1i9s16nqowbN%dont.spam.usenet@googlemail.com>
Injection-Date: Fri, 19 Nov 2021 18:30:40 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="873508"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Fri, 19 Nov 2021 18:30 UTC

In article <1piwmwf.1pl1i9s16nqowbN%dont.spam.usenet@googlemail.com>,
Hauke Fath <hauke@Espresso.Rhein-Neckar.DE> wrote:
....
>The problem is, this does not give you 'TERM is either unset, or empty'
>in one branch.
>
>For the background, the test is from csh.login where I want to run
>tset(1) only if TERM is not sane, to avoid side-effects. Since I just
>learned that "eval `tset -QIs ...`" will only produce a string, and not
>re-initialize the terminal, I am now running tset unconditionally.

How about:

if ! $?TERM set TERM=""
if $TERM == "" echo "TERM is unset or empty"

ObCrabbingAboutCSH: One thing that does annoy me is that "set" requires an
equals sign, but "setenv" does not. And by "requires", I mean it only
works one way. You have to always remember to use an "=" with "set" and to
NOT use one with "setenv".

--
Alice was something of a handful to her father, Theodore Roosevelt. He was
once asked by a visiting dignitary about parenting his spitfire of a daughter
and he replied, "I can be President of the United States, or I can control
Alice. I cannot possibly do both."

Re: Unset or empty variable test in (t)csh

<sn8qkc$ql14$2@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4614&group=comp.unix.shell#4614

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Unset or empty variable test in (t)csh
Date: Fri, 19 Nov 2021 18:32:44 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <sn8qkc$ql14$2@news.xmission.com>
References: <1piwk1d.1qnfocmjw81h7N%dont.spam.usenet@googlemail.com> <1piwodk.rj170lk47a9sN%dont.spam.usenet@googlemail.com>
Injection-Date: Fri, 19 Nov 2021 18:32:44 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="873508"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Fri, 19 Nov 2021 18:32 UTC

In article <1piwodk.rj170lk47a9sN%dont.spam.usenet@googlemail.com>,
Hauke Fath <hauke@Espresso.Rhein-Neckar.DE> wrote:
....
>FTR, I just came across [1] whose
>
>if ( ! ${?TERM} || { eval `if ( ${TERM} == "" ) exit 1` } ) ...
>
>fits my bill.

Wow. I had no idea...

--
People often ask what is the difference between liberals and conservatives.
It is this. Libs see the government helping them and are OK with the government
also helping other people. Cons see the government screwing them and are OK with
that as long as the government is also screwing other people.

Re: Unset or empty variable test in (t)csh

<1piwoyj.v7briefpmumsN%dont.spam.usenet@googlemail.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4615&group=comp.unix.shell#4615

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: dont.spa...@googlemail.com (Hauke Fath)
Newsgroups: comp.unix.shell
Subject: Re: Unset or empty variable test in (t)csh
Date: Fri, 19 Nov 2021 19:35:51 +0100
Organization: Meistens
Lines: 21
Message-ID: <1piwoyj.v7briefpmumsN%dont.spam.usenet@googlemail.com>
References: <1piwk1d.1qnfocmjw81h7N%dont.spam.usenet@googlemail.com> <1piwodk.rj170lk47a9sN%dont.spam.usenet@googlemail.com>
Reply-To: hauke@Espresso.Rhein-Neckar.DE (Hauke Fath)
X-Trace: individual.net 7jVe7JSzk4+rOTL2ux1ElA/jVXAd/P4Gv+4e4JgzwRtpmyyzJg
X-Orig-Path: dont.spam.usenet
Cancel-Lock: sha1:zVcE9DUbhiGL+aH9FsLYtqanNAU=
User-Agent: MacSOUP/D-2.8.6b1 (ed136d9b90) (Mac OS 10.13.6)
 by: Hauke Fath - Fri, 19 Nov 2021 18:35 UTC

Hauke Fath <dont.spam.usenet@googlemail.com> wrote:

> if ( ! ${?TERM} || { eval `if ( ${TERM} == "" ) exit 1` } ) ...

Alternatively[1],

if ( ! ${?TERM} ) set TERM = ""

then continue to check for an empty string.

So many ways to skin a cat...

Cheerio,
Hauke

[1]
<https://unix.stackexchange.com/questions/197497/how-to-check-if-string-is-blank-in-tcsh>

--
Now without signature.

Re: Unset or empty variable test in (t)csh

<sn8qv5$ql14$3@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4616&group=comp.unix.shell#4616

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Unset or empty variable test in (t)csh
Date: Fri, 19 Nov 2021 18:38:29 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <sn8qv5$ql14$3@news.xmission.com>
References: <1piwk1d.1qnfocmjw81h7N%dont.spam.usenet@googlemail.com> <1piwodk.rj170lk47a9sN%dont.spam.usenet@googlemail.com> <1piwoyj.v7briefpmumsN%dont.spam.usenet@googlemail.com>
Injection-Date: Fri, 19 Nov 2021 18:38:29 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="873508"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Fri, 19 Nov 2021 18:38 UTC

In article <1piwoyj.v7briefpmumsN%dont.spam.usenet@googlemail.com>,
Hauke Fath <hauke@Espresso.Rhein-Neckar.DE> wrote:
>Hauke Fath <dont.spam.usenet@googlemail.com> wrote:
>
>> if ( ! ${?TERM} || { eval `if ( ${TERM} == "" ) exit 1` } ) ...
>
>Alternatively[1],
>
>if ( ! ${?TERM} ) set TERM = ""
>
>then continue to check for an empty string.

I take it, you posted that w/o having read my most recent post on this
thread?

--
Q: How much do dead batteries cost?

A: Nothing. They are free of charge.

Re: Unset or empty variable test in (t)csh

<1piwuuz.o88pa8a90bmmN%dont.spam.usenet@googlemail.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4617&group=comp.unix.shell#4617

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: dont.spa...@googlemail.com (Hauke Fath)
Newsgroups: comp.unix.shell
Subject: Re: Unset or empty variable test in (t)csh
Date: Fri, 19 Nov 2021 21:41:05 +0100
Organization: Meistens
Lines: 18
Message-ID: <1piwuuz.o88pa8a90bmmN%dont.spam.usenet@googlemail.com>
References: <1piwk1d.1qnfocmjw81h7N%dont.spam.usenet@googlemail.com> <1piwodk.rj170lk47a9sN%dont.spam.usenet@googlemail.com> <1piwoyj.v7briefpmumsN%dont.spam.usenet@googlemail.com> <sn8qv5$ql14$3@news.xmission.com>
Reply-To: hauke@Espresso.Rhein-Neckar.DE (Hauke Fath)
X-Trace: individual.net GxqQlsA0qepH3ST4vWyBawGuxxZ4RA2t9HUcmdyi/XCSUbkRDu
X-Orig-Path: dont.spam.usenet
Cancel-Lock: sha1:/nb601dbFk9YYfHOwdWl3CZ4dwI=
User-Agent: MacSOUP/D-2.8.6b1 (ed136d9b90) (Mac OS 10.13.6)
 by: Hauke Fath - Fri, 19 Nov 2021 20:41 UTC

Kenny McCormack <gazelle@shell.xmission.com> wrote:

> >if ( ! ${?TERM} ) set TERM = ""
> >
> >then continue to check for an empty string.
>
> I take it, you posted that w/o having read my most recent post on this
> thread?

Right - our postings crossed each other. :)

USENET was not designed for chat mode...

Cheerio,
Hauke

--
Now without signature.

Re: Unset or empty variable test in (t)csh

<sn9542$qqub$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4618&group=comp.unix.shell#4618

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Unset or empty variable test in (t)csh
Date: Fri, 19 Nov 2021 21:31:46 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <sn9542$qqub$1@news.xmission.com>
References: <1piwk1d.1qnfocmjw81h7N%dont.spam.usenet@googlemail.com> <1piwoyj.v7briefpmumsN%dont.spam.usenet@googlemail.com> <sn8qv5$ql14$3@news.xmission.com> <1piwuuz.o88pa8a90bmmN%dont.spam.usenet@googlemail.com>
Injection-Date: Fri, 19 Nov 2021 21:31:46 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="879563"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Fri, 19 Nov 2021 21:31 UTC

In article <1piwuuz.o88pa8a90bmmN%dont.spam.usenet@googlemail.com>,
Hauke Fath <hauke@Espresso.Rhein-Neckar.DE> wrote:
>Kenny McCormack <gazelle@shell.xmission.com> wrote:
>
>> >if ( ! ${?TERM} ) set TERM = ""
>> >
>> >then continue to check for an empty string.
>>
>> I take it, you posted that w/o having read my most recent post on this
>> thread?
>
>Right - our postings crossed each other. :)
>
>USENET was not designed for chat mode...

Yup. So true.

--
Atheism:
It's like being the only sober person in the car, and nobody will let you drive.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor