更新VSCode集成终端的Bash版本 | MacOS

3
在MacOS上更新Bash并将其设置为默认shell后,遵循这些指示,我发现它对VSCode中的集成终端没有任何影响。如下所示: echo $0返回/bin/bash而不是/opt/homebrew/bin/bash echo $BASH_VERSION返回3.2.57(1)-release而不是5.1.12(1)-release(或更高版本)。
在VSCode中应用相同的指示,使用sudochsh上设置“Terminal > integrated > Default Profile: Osx”为“Bash”,都没有任何效果。如何解决这个问题?
简短的指导:
1. 使用Homebrew下载最新的Bash版本:brew install bash。 2. 使用Vim将已更新的版本(路径:/opt/homebrew/bin/bash)加入到/etc/shells白名单中。 3. 使用chsh -s /opt/homebrew/bin/bash将其设置为默认shell。

被采纳的答案在终端内运行bash脚本时不会更新bash版本。只有在直接执行命令时,才会更新集成终端的bash版本。 参考:Bash Version from inside the script is old and not what was explicitly defined in VSCODE settings · Issue #151230 · microsoft/vscode - Porcupine
1个回答

1

只需在settings.json中添加以下行即可覆盖原始路径(该文件位于设置内):

// "...",

"terminal.integrated.shell.osx": "/opt/homebrew/bin/bash",

// "...",

编辑

在我发布这个答案后,我发现这种方法已经过时了。

正确的方法是创建一个新的终端配置文件,并将其设置为默认配置文件:

// "...",

"terminal.integrated.profiles.osx": {
    "new bash": { // profile name
        "path": "/opt/homebrew/bin/bash"
    }
},

"terminal.integrated.defaultProfile.osx": "new bash",

// "...",

这个答案在集成终端上运行bash脚本时不会更新bash版本。它只会在直接执行命令时更新集成终端的bash版本。参考:Bash Version from inside the script is old and not what was explicitly defined in VSCODE settings · Issue #151230 · microsoft/vscode - Porcupine

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接