How does this line from Bash Script work?

I am trying to figure out how a specific line of code works from BASH tab completion man page script

[[ $OSTYPE == *@(darwin|freebsd|solaris|cygwin|openbsd)* ]] || _userland GNU \
    || return 1

I believe this is a guard; if the special BASH variable $OSTYPEdoes not contain one of the lines in the expression (basic regular?) contained in parentheses, or if userland is GNU, then it will terminate the script. But I can’t understand how the syntax works or what it means, and I don’t know what the control flow is.

You can find the definition _userland here :

# Check if we're running on the given userland
# @param $1 userland to check for
_userland()
{
    local userland=$( uname -s )
    [[ $userland == @(Linux|GNU/*) ]] && userland=GNU
    [[ $userland == $1 ]]
}

How does this feature work? Does it return a value?

If you could provide links to related documentation or articles, that would be helpful. Thank.

+2
1

c1 || c2 || c3 || ... , . .

, :

[[ $OSTYPE == *@(darwin|freebsd|solaris|cygwin|openbsd)* ]] \
|| _userland GNU \
|| return 1

OSTYPE darwin, freebsd .., . , , man bash, . :

@(pattern-list)
    Matches one of the given patterns

|. * @(...) , OSTYPE. @(...) , @(...)* , *@(...) .

OSTYPE , : _userland GNU. . , return 1, .

_userland :

  • local userland=$( uname -s ): uname -s userland
  • [[ $userland == @(Linux|GNU/*) ]] && userland=GNU: Linux GNU/, userland=GNU
  • [[ $userland == $1 ]]: . - . , .
+1

All Articles