Bash - 서브쉘을 생성하지 않고 연산자 우선순위를 명확히 하는 방법

Bash - 서브쉘을 생성하지 않고 연산자 우선순위를 명확히 하는 방법

분명 어딘가에 게시된 것 같은데 찾을 수가 없네요.

Bash에서 하위 셸을 만들지 않고 연산자 우선 순위(명령 그룹화라고도 함)를 어떻게 지정합니까? 이는 대부분의 다른 언어에서 수행되지만 ()Bash에서는 환경 변경 사항을 "삭제"하는 하위 쉘에서 명령을 실행합니다. 환경 변경 사항을 잃지 않고 연산자 우선 순위를 지정하고 싶습니다.

특히, 저는 다음과 같이 서브셸뿐만 아니라 다음과 같은 전체 스크립트 종료를 원합니다 ().

die ()
{
    echo "[DIE]: $1"
    exit 1
}

# When installChruby returns an error, print the error message and exit
[[ $CHRUBY =~ [Yy] ]] && (installChruby || die "Error installing chruby")

이렇게 하여 "해결 방법"을 찾았지만 원하는 만큼 좋지는 않습니다.

if [[ $CHRUBY =~ [Yy] ]]; then installChruby || die "Error installing Chruby"; fi 

원하는 결과는 설정되어 있지 않으면 아무것도 하지 않고 계속하고, 설정되어 있으면 CHRUBY함수를 호출하고 false를 반환하는 경우에만 함수를 호출하는 것입니다.installChrubyCHRUBYYydieinstallChruby

Bash에 이 작업을 수행할 수 있는 연산자가 있습니까 ? 아니면 Bash의 코드가 하위 쉘에서 실행되지 않도록 ()지시하는 방법이 있습니까 ?()

답변1

에서 man bash:

   { 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  metachar‐
          acters  (  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 metacharac‐
          ter.

관련 정보