[英]How to evaluate if a environment variable is set in vimrc
How to evaluate if an bash environment variable is set 如何评估bash环境变量是否已设置
for example 例如
function! Myfoo(arg)
if $SomeVar is set/exist ----> how to eval the SomeVar has been set
....
endif
endfunction
You've (intuitively?) used the correct syntax; 您(直觉上?)使用了正确的语法; as :help expression-syntax
explains (under :help expr-env
), the syntax is $VAR
. 如:help expression-syntax
解释(在:help expr-env
),语法为$VAR
。
You can compare with an empty string ( if $SomeVar != ""
) or use empty()
( if !empty($SomeVar)
) to check whether a (non-empty) value has been supplied. 您可以将其与空字符串进行比较( if $SomeVar != ""
),也可以使用empty()
( if !empty($SomeVar)
)检查是否已提供(非空)值。 It's not so easy to differentiate between empty environment variable and non-existing environment variable, so this is best avoided. 区分空的环境变量和不存在的环境变量并不是那么容易,因此最好避免这种情况。 (This distinction also is rarely used in shell scripts itself, neither.) (这种区别也很少在shell脚本本身中使用。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.