意外的令牌fi

时间:2012-12-18 11:26:24

标签: linux bash

#!/bin/bash
array=($1 $2 $3 $4)
if [ "$#" -ne 4 ]; then 
echo "Please enter Names"
else
for i in 1 2 3 4 5 
do 
echo "Welcome $i times"
done
echo "The Name is: "
fi

我在shell脚本中遇到语法错误:Unexpected token fi。请在脚本中指导我做错了。

1 个答案:

答案 0 :(得分:0)

你的脚本适用于GNU bash, version 4.2.39

$ ./test A B C D
Welcome 1 times
Welcome 2 times
Welcome 3 times
Welcome 4 times
Welcome 5 times
The Name is: 
$ cat test
#!/bin/bash
array=($1 $2 $3 $4)
if [ "$#" -ne 4 ]; then 
echo "Please enter Names"
else
for i in 1 2 3 4 5 
do 
echo "Welcome $i times"
done
echo "The Name is: "
fi