我正在尝试运行shell脚本,以便启动我正在处理的Meteor应用程序的本地版本。在此之前我从未使用过shell脚本,但是当我与主要开发人员合作时,它已经运行了。这是我的 run.sh 文件:
@echo off
c:
cd /Users/ten3/Desktop/git/ten/website/prospect-recovery/prospect-recovery
SET ROOT_URL=http://localhost
SET SPECIAL_RUN=no
SET NO_BATCH=no
SET NO_MAIL=no
SET MAIL_GUN_TEST=yes
SET MAIL_THROTTLE_INTERVAL=0
SET NODE_OPTIONS=%1
SET SHORT_URL=http://sota.ddns.net
SET NODE_PATH=%AppData%\npm
meteor --port 80
echo “works”
除了保持我的应用程序的本地副本与其他API交互之外,我对这些实际做的事情一无所知。每次我尝试运行脚本时都会得到:
run.sh: line 4: @echo: command not found
run.sh: line 6: c:: command not found
run.sh: line 10: SET: command not found
run.sh: line 12: SET: command not found
run.sh: line 14: SET: command not found
run.sh: line 16: SET: command not found
run.sh: line 18: SET: command not found
run.sh: line 20: SET: command not found
run.sh: line 22: SET: command not found
run.sh: line 24: SET: command not found
run.sh: line 26: SET: command not found
Error: listen EACCES
“works”
我尝试使用sudo更改文件权限,尝试在其查找的路径中包含文件位置,尝试在我的文件中包含bash,尝试在run.sh目录中运行文件,几乎所有内容我可以google。我无法弄清楚我错过了什么,想死。
答案 0 :(得分:1)
对于类似unix的操作系统,你应该为bash或其他shell重写它(有许多替代方案,bash
是最常见的)。
#!/bin/sh
cd /some/required/path
ROOT_URL='http://localhost'
SPECIAL_RUN='no'
...
NODE_OPTIONS="$1" # notice double quotes, single quotes don't perform $variable expansion
SHORT_URL="http://sota.ddns.net"
NODE_PATH=/actual/path/to/npm
export ROOT_URL SPECIAL_RUN ... NODE_OPTIONS SHORT_URL NODE_PATH
./meteor --port 80 # since the port is below 1024, it's privileged, and the script should be run from root. Use ports > 1024 to run as a user
要从给定目录运行程序或脚本,您可以指定/full/path/to/the/program
或只包括/path/to/the
到PATH
。默认情况下,出于安全原因,当前目录不在PATH中(与Windows不同)。