为什么此脚本在if语句中执行字符串:
#!/bin/bash
FILES="*"
STRING=''
for f in $FILES
do
if ["$STRING" = ""]
then
echo first
STRING='hello'
else
STRING="$STRING hello"
fi
done
echo $STRING
用sh script.sh输出时运行它:
first
lesscd.sh: line 7: [hello: command not found
lesscd.sh: line 7: [hello hello: command not found
lesscd.sh: line 7: [hello hello hello: command not found
lesscd.sh: line 7: [hello hello hello hello: command not found
lesscd.sh: line 7: [hello hello hello hello hello: command not found
hello hello hello hello hello hello
附:首次尝试shell脚本
谢谢
解决方法:
您正在尝试执行命令[hello.在之后放置一个空格[因此它将被认定为测试.
for f in $FILES
do
if [ "$STRING" = "" ]
then
echo first
STRING='hello'
else
STRING="$STRING hello"
fi
done
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。