1

我正在尝试编写一个进程来打开两个额外的 shell 窗口并向它们发送命令以运行我已安装的一些节点模块。这是我第一次编写 bash 脚本,所以如果我搞砸了,请随时告诉我。

我有这个脚本

#!/bin/bash

# [-g]
# [-h]
# [-l <location to start the http-server on --default ./>]
# [-p <port to start the http-server on --default "8111">]

run_gulp=false
run_http=false
run_http_port=8111
run_http_location=./

while getopts ghl:p: opt; do
    case $opt in
        g)
            run_gulp=true
            ;;
        h)
            run_http=true
            ;;
        l)
            run_http_location=$OPTARG
            ;;
        p)
            run_http_port=$OPTARG
            ;;
        \?)
            echo "Invalid option: -$OPTARG" >&2
            ;;
    esac
done

if [ $run_gulp == true ]
then
    start mintty "gulp" # this works
fi

if [ $run_http == true ]
then    
    start mintty "http-server $run_http_location -p $run_http_port"
fi

我将它放在我的 PATH 变量(我在 Windows 10 上)的一个文件夹中的一个名为 startdev 的文件中,所以我可以从任何地方打开一个 shell 并输入startdev -gstartdev -g -h运行它。

这一切都有效,我可以补充一点,当它打开 shell 并发送 gulp 命令时,它会检测到我的 gulpfile 并能够像我想要的那样在其上运行默认任务。但是,http-server 并没有做同样的事情,它只是告诉我http-server ./ -p 8111: No such file or directory

4

1 回答 1

1

Mintty 将第一个参数视为命令名称,以及由于 qoutes 而传递的所有选项。由其他程序启动的程序的参数(即使用 sudo、screen 等)通常作为单独的参数传递以避免解析,因此您应该尝试start mintty http-server $run_http_location -p $run_http_port不带引号。

于 2016-03-10T00:23:56.550 回答