Windows下VS Code执行bash编译脚本报错:bash未被识别
解决Windows下VS Code执行Shell脚本报错问题
1. 解决"bash未被识别"的问题
Windows系统默认没有内置bash环境,需先安装对应环境:
- 方案一:安装WSL(Windows Subsystem for Linux)
打开管理员权限的PowerShell,执行命令:
重启电脑后选择一个Linux发行版(如Ubuntu)完成安装,之后VS Code内置终端即可直接使用bash命令。wsl --install - 方案二:安装Git Bash
下载安装Git后,在VS Code中配置默认终端为Git Bash:- 打开VS Code设置(快捷键
Ctrl+,) - 搜索
terminal.integrated.profiles.windows,点击"编辑 in settings.json" - 添加Git Bash配置并设为默认:
"terminal.integrated.profiles.windows": { "Git Bash": { "path": "C:\\Program Files\\Git\\bin\\bash.exe" } }, "terminal.integrated.defaultProfile.windows": "Git Bash"
- 打开VS Code设置(快捷键
2. 修复Shell脚本错误
你的脚本存在两处问题:
- Shebang行无效:
#!/bin/ch是错误写法,需改为#!/bin/bash - 编译
.so文件是Linux动态库操作,必须在Linux环境(如WSL)下执行,Git Bash的MinGW仅能生成Windows的.dll文件。若目标是Linux动态库,确保在WSL终端内运行脚本。
修改后的脚本:
#!/bin/bash echo "Compilando MixMaster MOD" gcc -shared -w -m32 -pthread -Wall -static Injection.cpp Script.cpp CScriptManager.cpp CMemory.cpp CHookManager.cpp CEventsHandler.cpp liblua52.a -ldl -o ../Injection.so -masm=intel
3. 正确执行脚本
在配置好的bash终端中,先给脚本添加执行权限:
chmod +x compile.sh
再执行脚本:
./compile.sh
内容的提问来源于stack exchange,提问作者yasmine B
相关产品推荐
相关产品推荐

