if和之间必须有一个空格
[,如下所示:
#!/bin/bash#test file existsFILE="1"if [ -e "$FILE" ]; then if [ -f "$FILE" ]; then echo :"$FILE is a regular file" fi...
这些(及其组合)也都是 不正确的 :
if [-e "$FILE" ]; thenif [ -e"$FILE" ]; thenif [ -e "$FILE"]; then
另一方面,这些都可以:
if [ -e "$FILE" ];then # no spaces around ;if [ -e "$FILE" ] ; then # 1 or more spaces are ok
顺便说一句,这些是等效的:
if [ -e "$FILE" ]; thenif test -e "$FILE"; then
这些也等效:
if [ -e "$FILE" ]; then echo exists; fi[ -e "$FILE" ] && echo existstest -e "$FILE" && echo exists
而且,您的脚本的中间部分应该
elif像这样更好:
if [ -f "$FILE" ]; then echo $FILE is a regular fileelif [ -d "$FILE" ]; then echo $FILE is a directoryfi
(我也将引号中的引号删除了
echo,因为在此示例中引号是不必要的)



