bash - 在 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\bin
GitBash 的目录:
. ./VagrantGuestScript.sh
然后当我执行这个脚本的“fcc”函数时,它只执行前 2 或 3 行,然后关闭终端。
谁能解释为什么它在尝试注册脚本时打开 Gitbash 的 bin 路径以及为什么它在只执行 2/3 行函数“fcc”后关闭终端?
解决方案
推荐阅读
- javascript - 如何在asp.net核心的Datatable中搜索动态列?
- python - PyGame 中 PAINT 程序的问题
- flutter - 带有 PopupMenuButton 的不同屏幕
- r - 将不同的连续过滤器应用于数据表的快速方法是什么
- security - 如何验证私有和公共 VAPID 密钥是否正确?
- firebase - 如何让firebase按日期顺序存储文件?
- json - 在 Powershell 中合并 2 个 JSON 文件的问题
- ios - 在 iOS 上通过 Messages 发送和接收自定义文件包的正确方法是什么?
- javascript - 响应中“Access-Control-Allow-Origin”标头的值不能是通配符“*”,但在我的服务器中它不是通配符
- php - Laravel 队列即使在尝试计数后仍处于处理状态