简体   繁体   中英

clarification regarding an if statement in ksh

Im quite new to ksh scripting, please bear with me, if this is too obvious

What does this mean in ksh? Is this also a way to write an if condition?

[[ -n $MSRV_SGL ]] && {
    msrv_ps || return 1
}

msrv_ps is a function

How does this read? if the length of string $MSRV_SGL is non zero.... ?

I havent come across such expressions in any online examples.

Yes is telling you: if var length is not zero, execute function and return 1 if it's exit code is not zero.

It can be constructed as:

if [[ -n $MSRV_SGL ]];then
   if  ! msrv_ps;then 
      return 1
   fi 
fi

{ list; } list is simply executed in the current shell environment. list must be terminated with a newline or semicolon. This is known as a group command. The return status is the exit status of list. Note that unlike the metacharacters ( and ), { and } are reserved words and must occur where a reserved word is permitted to be recognized. Since they do not cause a word break, they must be separated from list by whitespace or another shell metacharacter.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM