我希望能使用grep來檢查,看看是否權限已正確設置上的文件...我如何在grep中使用「 - 」字符?
我知道下面的情況可能不理想&不簡明,因爲它可能是,但我個別屬性,如車主姓名和權限...
後,我打算用這樣的:
cd ~/Desktop
if [ `ls -a | grep My File.txt | wc -l` -eq 1 ];
then
echo "My File.txt Exists"
MYPERMISSIONS=`ls -l My File.txt`
if [ `$MYPERMISSIONS | grep $"\-rwxr\-xr\-x" | wc -l` -eq 1 ];
then
echo "Permissions are correct for My File.txt"
fi
if [ `$MYPERMISSIONS | grep $"\-rwxr\-xr\-x" | wc -l` -eq 0 ];
then
echo "Permissions are NOT correct for My File.txt"
fi
if [ `$MYPERMISSIONS | grep root | wc -l` -eq 1 ];
then
echo "Owner is correct for My File.txt"
fi
if [ `$MYPERMISSIONS | grep root | wc -l` -eq 0 ];
then
echo "Owner is NOT correct for My File.txt"
fi
fi
if [ `ls -a | grep My File.txt | wc -l` -eq 0 ];
then
echo "My File.txt does NOT Exist"
fi
它看起來像grep的不想要搜索的「 - 」字符.. 。
任何繞過這個方法?
謝謝!
你是怎麼推斷的grep是無視「 - 」字符? – vinothkr 2011-05-31 05:19:50