簡體   English   中英

Bash權限被拒絕

[英]Bash permission denied

我是bash的初學者,我不明白為什么

#! /bin/sh
if ! [ -d $1 ]; then echo This is not a directory && exit 1; fi

for file in `ls $1`; 
do 
    if [ -f `$1/$file` ]; then
        echo $file is a file
    elif [ -d $file ]; then
        echo $file is a directory
    fi
done

給我[ -f $ 1 / $ file ]權限被拒絕

這是因為您已在if的行中用反引號(``)包圍了路徑。 這告訴外殼程序執行文件(毫無疑問,文件夾中的許多文件都不可執行,因此是錯誤)。 切換為普通報價。

順便說一句,在“ for”循環中使用反引號捕獲“ ls”的輸出是一個壞主意-它會破壞包含空格的文件名(這是完全合法的)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM