【问题标题】:Unable to load .bash_profile or .bashrc when running VSCode tasks on windows 10在 Windows 10 上运行 VSCode 任务时无法加载 .bash_profile 或 .bashrc
【发布时间】:2019-07-01 12:36:36
【问题描述】:

我在 Windows 10 Home 上使用 VSCode 版本 1.31.0。我启用了 WSL,并安装了一些东西,如 nvm、pyenv 等,这需要在 .bashrc.bash_profile 上运行所需的额外脚本

例如.bashrc:

export PATH="/custom/path:$PATH"

运行集成 shell (CTRL + `) 时,一切正常,我可以看到 $PATH 包括 /custom/path

但是当我尝试运行一个任务脚本时(https://code.visualstudio.com/docs/editor/tasks#vscode

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "eslint",
            "problemMatcher": [
                "$eslint-stylish"
            ]
        },
        {
            "label": "Run tests",
            "type": "shell",
            "command": "./scripts/test.sh",
            "presentation": {
                "reveal": "always",
                "panel": "new"
            }
        }        
    ]
}

test.sh中的内容

echo $PATH

当我尝试运行“运行测试”任务时,它不显示/custom/path,或者实际上,不包括~/.bashrc~/.bash_profile 中的任何内容。

我什至在 test.sh 中尝试过类似的东西,但它仍然没有加载我的 .bashrc

source /home/user/.bashrc
echo $PATH

以下是我的 VSCode 用户设置:

{
    "terminal.external.windowsExec": "C:\\windows\\Sysnative\\bash.exe",
    "terminal.integrated.shell.windows": "C:\\windows\\Sysnative\\bash.exe",
    "terminal.integrated.shellArgs.windows": ["--login"],
    "eslint.provideLintTask": true
}

问题是:

如何设置 VSCode 或 windows 以使用我的 .bashrc.bash_profile 运行任务?

【问题讨论】:

    标签: windows bash shell terminal visual-studio-code


    【解决方案1】:

    这是因为我的.bashrc中的以下几行

    # If not running interactively, don't do anything
    case $- in    
        *i*) ;;      
          *) return;;
    esac#
    

    所以在我更新了如下所示的 VSCode 设置后:

    {
        "terminal.external.windowsExec": "C:\\windows\\Sysnative\\bash.exe",
        "terminal.integrated.shell.windows": "C:\\windows\\Sysnative\\bash.exe",
        "terminal.integrated.shellArgs.windows": ["-i"],
        "eslint.provideLintTask": true
    }
    

    我的.bashrc中剩下的命令都会被执行

    【讨论】:

      猜你喜欢
      • 2019-08-02
      • 2019-01-20
      • 2019-03-17
      • 1970-01-01
      • 2020-07-28
      • 2015-11-02
      • 2018-11-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多