0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

msrv_ps || return 1 does not mean msrv_ps; return 1. Should be if ! msrv_ps; then return 1; fi.
You're abolutely right, i was thinking on && operator :) . Thanks @whjm
Thank you.. that clarified things :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.