shell 无法使用VSCode调试bash脚本

ergxz8rk  于 12个月前  发布在  Shell
关注(0)|答案(3)|浏览(261)

我已经安装了带有Bash调试扩展的VSCode。
在此之前,我已经安装了bashdb,并使用bashdb --version验证了它的版本,它是4.4。
现在,扩展创建了一个名为launch.json的空文件。
我写了下面的代码来开始调试,但是仍然什么都没有发生

{
    "version": "0.2.0",
   
    "scriptPath": "${command:SelectScriptName}",
 
    "configurations": [
    ],
    "compounds": [
        {
            "type": "bashdb",
            "name": "Compound",
            "configurations": []
        }
    ]
}

我应该怎么做才能启用调试?

bxjv4tth

bxjv4tth1#

安装bashdb扩展后,将以下代码块添加到launch.json文件中。此配置允许您调试当前在VS Code上打开的脚本。因此,为了开始调试脚本,您必须在VS Code上打开它,并键入F5以开始调试它。或者,也可以在VS Code上打开相同的脚本,在VS Code左栏上打开Run and Debug菜单,然后单击Play

{
  "type": "bashdb",
  "request": "launch",
  "name": "Bash-Debug (simplest configuration)",
  "cwd": "${workspaceFolder}",
  "program": "${file}",
  "showDebugOutput": true,
  "terminalKind": "integrated"
}

args参数添加到上面的块中,允许您在调试时将带有参数的数组传递给脚本。

vmdwslir

vmdwslir2#

我用Bash扩展测试了这段代码:

{
  "version": "0.2.0",
  "configurations": 
  [
    {
        "type": "bashdb",
        "request": "launch",
        "name": "Bash-Debug (select script from list of sh files)",
        "cwd": "${workspaceFolder}",
        "program": "${command:SelectScriptName}",
        "args": []
    }
  ]
}

Visual Studio Code显示项目中的脚本列表,您可以选择要运行的脚本。您也可以选择一个“Bash-Script(硬编码脚本名称)”配置,它允许硬编码脚本路径。

nue99wik

nue99wik3#

如果你想调试一个Bash脚本,我建议你使用-x标志来执行你的脚本。举例来说:

bash -x script.sh

或者在脚本中添加:

set -x 
<DEBUG_CODE_LINES>
set +x

相关问题