close

稍微記一下 shell script 的 if 用法

 

if [ -f /tmp/file.txt ]; then


else


fi

 

-f : 檔案存在

-d : 目錄存在

-r : 執行此腳本的使用者對 file 具有讀取權限

-w : 執行此腳本的使用者對 file 具有寫入權限

-x : 執行此腳本的使用者對 file 具有執行權限

-e : 不論格式,只要存在及成立

-s : 存在,並且檔案 size 非 0

-u : 檔案具有 SUID 的屬性

-g : 檔案具有 SGID 的屬性

-k : 檔案具有 Sticky bit 的屬性

-c : 檔案是一個 character device

-b : 檔案是一個 block device

-p : 檔案是一個 named pipe

-L : 檔案是一個 symbolic link

[ file1 -nt file2 ] file1 比 file2 新

[ file1 -ot file2 ] file1 比 file2 舊

上述兩者皆已最後存取時間為主

[ s1 = s2 ] 字串 1 與字串 2 相等則成立

[ s1 != s2 ] 字串 1 與字串 2 不相等則成立

[ n1 -eq n2 ] n1 與 n2 相等則成立

[ n1 -ne n2 ] n1 與 n2 不相等則成立

[ n1 -gt n2 ] n1 > n2 則成立

[ n1 -ge n2 ] n1 >= n2 則成立

[ n1 -lt n2 ] n1 < n2 則成立

[ n1 -le n2 ] n1 <= n2 則成立

arrow
arrow
    文章標籤
    script linux
    全站熱搜
    創作者介紹
    創作者 rex5405 的頭像
    rex5405

    雷射's zone

    rex5405 發表在 痞客邦 留言(0) 人氣()