[英]shell script that takes a file name as an argument and deletes this file from every directory above the pwd in Unix / Linux / Ubuntu
我的shell腳本如下。
if [ $# -eq 0 ]
then
echo "pass the file name"
exit
fi
fl=$1
ch=1
h=/home
while [ $ch -eq 1 ]
do
cd ..
p=`pwd`
echo "$p/$fl"
rm `echo "$p/$fl"` 2> /dev/nullif [ $p = $h ]
then
ch=0
fi
done
但執行時顯示語法錯誤。 line16:意外令牌附近的語法錯誤then' line 16:
然后'
這個腳本有什么錯誤?
如果腳本你放錯了地方。
if [ $# -eq 0 ]
then
echo "pass the file name"
exit
fi
fl=$1
ch=1
h=/home
while [ $ch -eq 1 ]
do
cd ..
p=`pwd`
echo "$p/$fl"
rm `echo "$p/$fl"` 2> /dev/null
if [ $p = $h ]
then
ch=0
fi
done
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.