Ros*_*oss 3 unix linux bash shell
为什么此脚本在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
Run Code Online (Sandbox Code Playgroud)
用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
Run Code Online (Sandbox Code Playgroud)
ps首先尝试shell脚本
谢谢
您正在尝试执行该命令[hello
.之后放置一个空格[
,它将被视为一个测试.
for f in $FILES
do
if [ "$STRING" = "" ]
then
echo first
STRING='hello'
else
STRING="$STRING hello"
fi
done
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
352 次 |
最近记录: |