【问题标题】:Shell script returns: run.sh: line 10: SET: command not foundShell 脚本返回:run.sh:第 10 行:SET:找不到命令
【发布时间】:2015-11-25 22:45:41
【问题描述】:

我正在尝试运行一个 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 目录中运行文件,几乎所有内容我可以谷歌。我无法弄清楚我错过了什么,并且想死。

【问题讨论】:

  • 此脚本适用于 Windows
  • @user3159253 我以前可以在我的 Mac 上运行它,在帮助下。我的首席开发人员使用 Windows。
  • 这是一个 Windows 批处理脚本,而不是 Unix bash 脚本。
  • 我投票决定将此问题作为离题结束,因为所描述的问题无法使用真正为 UNIX shell 编写的脚本来重现。

标签: macos bash shell meteor


【解决方案1】:

您应该为 bash 或其他类似 unix 的操作系统的 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 不同)。

【讨论】:

  • 啊,好吧。 bash 脚本是否需要 cd 到我的流星应用程序文件夹中?或者这仅仅是因为我可以从那里启动我的本地服务器吗?
  • 是 ':c' 和 'SET' 死的赠品,它是为 Windows 使用的吗?
  • 是的,c: 表示您切换到“C:”卷。类 Unix 系统有一个 / ,所有卷都附加到 / 下的某个点(参见 man mount
  • 我还建议在最后一行添加execexec ./meteor --port 80;这样,在调用meteor 之后,bash 解释器就不会留在内存中。
  • 你也可以考虑set -a,自动导出所有分配给环境的shell变量;这样,export 命令就不需要使用单独的列表来维护。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-08-17
  • 1970-01-01
  • 2016-10-07
  • 1970-01-01
  • 2023-02-18
  • 2017-08-15
  • 2013-03-18
相关资源
最近更新 更多