【问题标题】:How can I debug WSL Bash script如何调试 WSL Bash 脚本
【发布时间】:2018-12-08 08:58:50
【问题描述】:

我有一个在 WSL 中运行的 bash 脚本,它也调用其他脚本,手动调试对我来说相当复杂,所以我决定尝试在 VS 代码中调试它。问题是它似乎无法访问完整的 WSL 功能。

以下是它的设置方式:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "bashdb",
            "request": "launch",
            "name": "Bash-Debug (simplest configuration)",
            "program": "E:/Documents/Code/AndroidBuild/AndroidBuild.sh"
        }
    ]
}

当我运行时,它似乎只能访问最简单的 bash 命令,而无法访问安装在 WSL 上的组件:

PS E:\Documents\Code> cd '.'; & 'wsl.exe' 'bash' '-c' 'cd "/mnt/e/Documents/Code"; while [[ ! -p "/tmp/vscode-bash-debug-fifo-12281" ]]; do sleep 0.25; done; "bash" "/mnt/c/Users/Jzuken/.vscode/extensions/rogalmic.bash-debug-0.3.3/bashdb_dir/bashdb" --quiet --tty "/tmp/vscode-bash-debug-fifo-12281" --tty_in "/tmp/vscode-bash-debug-fifo-12281_in" --library "/mnt/c/Users/Jzuken/.vscode/extensions/rogalmic.bash-debug-0.3.3/bashdb_dir" -- "/mnt/e/Documents/Code/AndroidBuild/AndroidBuild.sh" '
Hello World
/mnt/e/Documents/Code/AndroidBuild/AndroidBuild.sh: line 2: $'screenfetch\r': command not found

AndroidBuild.sh:

echo "Hello World"
screenfetch

如您所见,echo 工作正常,但 screenfetch 不起作用,即使我在 WSL 中运行它也是如此。

如何设置它以便我可以使用 VS 代码在本机 WSL 环境中调试 bash 脚本?我还在我的 WSL 上运行 ssh 服务器,我可以连接到它,如果有帮助的话。

【问题讨论】:

    标签: bash debugging visual-studio-code windows-subsystem-for-linux


    【解决方案1】:

    简而言之,您可以将 bashdb 作为 WSL 中的命令行调试器安装,无论是从源代码还是作为一个包。例如https://packages.ubuntu.com/xenial/bashdb

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-31
      • 1970-01-01
      • 2013-10-21
      • 2020-05-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多