#!/bin/sh
read -p "Input a file or directory what you want " x
for FILENAME in `ls`
do
if [ -e $FILENAME ]
then
echo "File exist" #if file exist, you should show me that is it a directory
# or symboliclink ...for so on like that
elif [ -d $FILENAME ]
then
echo " It is a directory"
elif [ -L $FILENAME ]
then
echo " It is a symbolic link"
elif [ -c $FILENAME ]
then
echo " It is a character tool file"
elif [ -b $FILENAME ]
then
echo " It is a block tool"
elif [ -p $FILENAME ]
then
echo " It is a pipe "
elif [ -S $FILENAME ]
then
echo " It is a socket"
elif [ -f $FILENAME ]
then
echo " It is a ordinary file"
else
echo " file isn`t exist"
fi
done
错误消息是
./fn: line 43: unexpected EOF while looking for matching ``'
./fn: line 48: syntax error: unexpected end of file
答案 0 :(得分:4)
您在echo "file isn't exist"
中使用的是反引号而不是撇号。如果你真的想在那里使用错误的字符,你需要转义它以防止shell将其解释为命令替换的开头:
echo "file isn\`t exist"
错误消息不是特别清楚,因为它使用反引号来模拟开头的单引号。 intent 是一种类似
的ASCII呈现./ fn:第43行:寻找匹配的'''
时意外的EOF
但最终结果有点令人困惑。