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.
ObHint: " | sed '/csh.*harmful/d'"
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
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.
FTR, I just came across [1] whose
if ( ! ${?TERM} || { eval `if ( ${TERM} == "" ) exit 1` } ) ...
fits my bill.
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.
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.
if ( ! ${?TERM} || { eval `if ( ${TERM} == "" ) exit 1` } ) ...
The naive
if ( ! ${?TERM} || ${TERM} == "" ) ...
errors out in the second expression
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?
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...
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 57:33:28 |
Calls: | 6,652 |
Calls today: | 4 |
Files: | 12,200 |
Messages: | 5,331,023 |