How to evaluate if an bash environment variable is set
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
.
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. 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.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.