2017-05-29 72 views
-2
#!/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 
+1

'=撇號,'=反向。 「不」需要一個撇號,而不是一個反作用。 – PSkocik

回答

4

您使用的是反引號,而不是在echo "file isn't exist"撇號。如果你真的想那裏使用了錯誤的字符,你需要逃脫,以防止shell解釋它作爲一個命令替換的開頭:

echo "file isn\`t exist" 

錯誤信息不是特別清楚,因爲它使用反引號來模擬單引號。該意圖是的東西的ASCII渲染像

./fn:第43行:意外的EOF而尋找匹配‘`’

但最終的結果卻有點混亂。

相關問題