How can I check if a variable is empty or not in tcsh Shell?

后端 未结 3 718
借酒劲吻你
借酒劲吻你 2021-01-01 09:47

IF I have to check that if a variable is empty or not for that in bash shell i can check with the following script:

if [ -z \"$1\" ] 
then
    echo \"variabl         


        
3条回答
  •  隐瞒了意图╮
    2021-01-01 10:03

    You can try this (found here):

    set name
    if ( ${%name} == 0 ) then
            echo " Variable name has 0 characters as value."
    endif
    

    Note that the person who posted this has the following signature:

    Standard advice: avoid csh family for scripting.

    Note: This will break if name is an environment variable.

    setenv name foobar ; set name ; echo '+++'$name'+++' ; unset name ; echo '==='$name'==='
    
    ++++++
    ===foobar===
    

提交回复
热议问题