我學習bash和希望你們能幫助我發生了什麼事情與下面的腳本bash腳本給出錯誤的輸出
#!/bin/bash
#primer if
if [ -f $file1 ]; then
echo "file1 is a file"
else
echo "file1 is not a regular file"
fi
#segundo if
if [ -r $file1 ]; then
echo "file1 has read permission"
else
echo "file1 doesnot have read permission"
fi
#tercer if
if [ -w $file1 ]; then
echo "file1 has write permission"
else
echo "file1 doesnot have write permission"
fi
#cuarto if
if [ -x $file1 ]; then
echo "file1 has execute permission"
else
echo "file1 doesnot have execute permission"
fi
它看起來對我說,如果我改變了也沒關係文件的權限,因爲輸出始終是相同的
[email protected]:~/Books/2012/ubuntu_unleashed$ ./script.sh
file1 is a file
file1 has read permission
file1 has write permission
file1 has execute permission
[email protected]:~/Books/2012/ubuntu_unleashed$ ll file1
-rw-r--r-- 1 fmp fmp 0 Aug 30 13:21 file1
[email protected]:~/Books/2012/ubuntu_unleashed$ chmod 200 file1
[email protected]:~/Books/2012/ubuntu_unleashed$ ./script.sh
file1 is a file
file1 has read permission
file1 has write permission
file1 has execute permission
[email protected]:~/Books/2012/ubuntu_unleashed$ ll file1
--w------- 1 fmp fmp 0 Aug 30 13:21 file1
[email protected]:~/Books/2012/ubuntu_unleashed$ chmod 000 file1
[email protected]:~/Books/2012/ubuntu_unleashed$ ll file1
---------- 1 fmp fmp 0 Aug 30 13:21 file1
[email protected]:~/Books/2012/ubuntu_unleashed$ ./script.sh
file1 is a file
file1 has read permission
file1 has write permission
file1 has execute permission
文件1可以爲空或不是靜態輸出是一樣的,做同樣的測試
任何人能向我解釋什麼是wron G?
感謝
BTW這裏的腳本是compare3 Ubuntu的解開了書2011版(圖書網站http://ubuntuunleashed.com/)的233頁上的修改版本
設置僅用於tcsh還是bash? – murpholinox
是的,'set'它也可以在bash中使用 – higuaro