首页 > 解决方案 > 在 Windows GitBash 中从 Shell 脚本执行单个函数会意外关闭 shell

问题描述

我最近在我的 Windows 64Bit(Windows 7 和 10,在两个系统中)中安装了Git For Windows版本 2.19.1.windows.1。

现在我创建了下面的脚本来轻松地完成一些常规任务,而无需单独编写每条指令:

#!/bin/bash
## Contains functions and methods that can be executed inside Vagrant SSH Session

export SCRIPT_PATH="$(cd "$(dirname "$0")"; pwd -P)"
export PROJECT_ROOT_PATH="/var/www" PROJECT_ROOT_DIR="/var/www" ROOT_FOLDER="/var/www"

function fcc() {
    echo "########## Frontend Cache clear begins #############"
    [[ "$PWD" =~ "frontend/app" ]] && cd frontend/app
    rm -rf webroot/cache_js && rm -rf webroot/cache_css
    mkdir -m 777 webroot/cache_js && mkdir -m 777 webroot/cache_css
    Console/cake AssetCompress.AssetCompress build -f
    cat /dev/null > ~/.bash_history && history -wc && history -cw && exit
    cd /var/www
    echo "########## Frontend Cache clear ends #############"
    keep_shell_open
}

function bocc() {
    ...
}

function bcc() {
    ...
}

function succ() {
    ...
}

function keep_shell_open() { exec $SHELL; };

现在,当 goto 脚本的目录通过 Gitbash 终端时,我将脚本注册如下,它意外地打开了C:\Program Files\Git\usr\binGitBash 的目录:

. ./VagrantGuestScript.sh

然后当我执行这个脚本的“fcc”函数时,它只执行前 2 或 3 行,然后关闭终端。

谁能解释为什么它在尝试注册脚本时打开 Gitbash 的 bin 路径以及为什么它在只执行 2/3 行函数“fcc”后关闭终端?

标签: bashfunctionterminalwindows-7git-bash

解决方案


推荐阅读