[MacOS] bash 버전업


맥에 기본적으로 설치된 bash 버전은 3.x입니다. 버전이 낮아 여러가지로 불편한 점이 있습니다.

 

$ bash --version
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin21)
Copyright (C) 2007 Free Software Foundation, Inc.

배시 버전은 --version으로 확인할 수 있습니다.

 

$ brew install bash
$ bash --version
GNU bash, version 5.2.2(1)-release (aarch64-apple-darwin21.6.0)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

brew 등으로 최신 버전 bash를 설치할 수 있습니다.

설치 후 쉘 재시작이 필요합니다

 

$ which bash
/opt/homebrew/bin/bash

arm mac의 경우 /opt/homebrew/bin/bash에 설치됩니다. which로 설치 위치 확인 가능합니다.

 

#!/opt/homebrew/bin/bash

echo $BASH_VERSION
declare -A arr
#...

/bin/bash는 여전히 3.x 버전입니다.

./script.sh 처럼 스크립트 실행했을 때 새로 설치한 bash로 실행되게 하려면 위처럼 #!{bash 설치경로}를 써 주셔야 합니다.

반응형