You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下VS Code执行bash编译脚本报错:bash未被识别

解决Windows下VS Code执行Shell脚本报错问题

1. 解决"bash未被识别"的问题

Windows系统默认没有内置bash环境,需先安装对应环境:

  • 方案一:安装WSL(Windows Subsystem for Linux)
    打开管理员权限的PowerShell,执行命令:
    wsl --install
    
    重启电脑后选择一个Linux发行版(如Ubuntu)完成安装,之后VS Code内置终端即可直接使用bash命令。
  • 方案二:安装Git Bash
    下载安装Git后,在VS Code中配置默认终端为Git Bash:
    1. 打开VS Code设置(快捷键Ctrl+,)
    2. 搜索terminal.integrated.profiles.windows,点击"编辑 in settings.json"
    3. 添加Git Bash配置并设为默认:
      "terminal.integrated.profiles.windows": {
          "Git Bash": {
              "path": "C:\\Program Files\\Git\\bin\\bash.exe"
          }
      },
      "terminal.integrated.defaultProfile.windows": "Git Bash"
      
    保存后重启终端,即可使用bash命令。

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 05:02:09