csh - why does the if always print empty? attempting to test whether passed in variable is set? -


i'm trying write csh alias (and yes has csh, god wish didn't). i'd pass in variable name , depending on whether set or not operate on it. i've boiled code down following. puzzles me first echo prints 1 or 0 depending on if value set or not, echo in if prints empty.

alias trythis 'eval echo \$\?\!:1 ; eval if \$\?\!:1 ; echo empty ; endif ; ' 

what's suppose happen if pass in path shouldn't print anything, if pass in pathx should print empty. (and yes, if backwards, ripped out ! make things simpler)

so trythis path should print empty, , trythis pathx should print nothing

the misleading part original code didn't have semi-colons escaped second eval statement, e.g. following part:

eval if \$\?\!:1 ; echo empty ; endif ;

here have 3 statements executed shell:

  • eval if \$\?\!:1 then - silently fail / do-nothing
  • echo empty - print empty
  • endif - nothing (not sure why csh doesn't complain here)

here's updated version escape semi-colons execute previous 3 statements single statement:

alias trythis 'eval echo \$\?\!:1 ; eval if \$\?\!:1 \; echo empty \; endif ;'

i'm not sure mean when want put multiple commands in if. looking way test results of multiple commands in 1 single if statement or else? perhaps new stack overflow question.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -