好的,这是一个非常简单的小事情,但它已经到了点,我已经用尽2-3个小时,试图找出为什么这是无效的,但没有得到任何进展。
我正在尝试制作Bash/Shell脚本程序,在其中的一个点上,我想检查字符串数组的内容,以确定字符串是否为空。我的代码如下:
#Display any words the user corrected, and what he/she corrected it with (ignore blank corrections)
printf "\n\n" "MISPELLED / CORRECTIONS"
for (( i=0; i<${#words[*]}; i++)); do
if [!"${corrections[$i]}"=""]; then //this is line 25
printf "\n ${words[$i]} ${corrections[$i]}"
fi
done我不确定如果我用的方式!操作符是合法的,但是不管有没有它,我都会得到运行时错误:
./test:第25行:=:未找到命令
如果需要的话,我可以发布其余的代码,尽管我很有信心“更正”数组被正确地填充了字符串。
发布于 2014-10-07 23:21:44
在shell中,[是一个命令,所以在它之前和之后留下空格是很重要的。此外,如果要检查字符串是否为空,则可以使用-n。
if [ -n "${corrections[$i]}" ]https://stackoverflow.com/questions/26246706
复制相似问题