【发布时间】:2014-11-08 21:15:23
【问题描述】:
发现这个错误很奇怪,因为以前我的脚本正在运行,但是在我将它从我正在处理的服务器上移到我的本地计算机后,它停止了工作,只是给了我一个“意外的操作员”错误。
# Else if the script is being run in the arrayscripts directory, add /output/ ...
elif [ $basePath == "arrayscripts" ];
then
echo "$dscr has started to run."
cpuPath="`pwd`/output/cpu.binary"
txtPath="`pwd`/output/cpu.txt"
csvPath="`pwd`/output/cpu.csv"
【问题讨论】:
-
您可能使用 POSIX shell 运行它,可能是
dash(在 Ubuntu 中默认为sh),它不支持==。见Bashisms -
如果这个 shell 是 bash,明显的问题是缺少引号。
"$basePath"与$basePath不一样——不带引号,后者可以扩展为任意数量的参数,这使得它放在运算符位置的内容完全不可预测。 -
既然你标记了这个
bash,你的脚本是用#!/bin/bash开始的吗?如果没有,您应该这样做。 -
@CharlesDuffy 以 #!/bin/sh 开头以为是 bash,抱歉标记错误
-
仅供参考,使用
`pwd`的效率远低于$PWD。