文件比較容許你測試Linux 文件系統上文件和目錄的狀態shell
比較 | 描述 |
-d file | 檢查file是否存在並是一個目錄 |
-e file | 檢查file是否存在 |
-f file | 檢查file是否存在並是一個文件 |
-r file | 檢查file是否存在並可讀 |
-s file | 檢查file是否存在並不是空 |
-w file | 檢查file是否存在並可寫 |
-x file | 檢查file是否存在並可執行 |
-O file | 檢查file是否存在並屬當前用戶全部 |
-G file | 檢查file是否存在而且默認組與當前用戶相同 |
file1 -nt file2 | 檢查file1 是否比file2 新 |
file1 -ot file2 | 檢查file1 是否比file2 舊 |
jump_directory=/home/wa/bash
if [-d $jump_directory]測試
then字符串
若是jump_directory存在並是一個目錄,那麼then 後面的命令將會被執行字符串處理
if -then 語句容許你使用布爾邏輯來組合測試,有兩種布爾運算可用數學
[condition1] &&[condition2] 兩個條件都知足,then 部分的代碼纔會執行it
[condition1] || [condition2] 只要知足一個條件,then 部分的代碼就會被執行io
bash shell提供了兩項能夠在if -then 語句中使用的高級特性:table
使用雙括號file
符號 | 描述 |
var++ | 後增 |
var-- | 後減 |
++var | 先增 |
--var | 先減 |
! | 邏輯求反 |
~ | 位求反 |
** | 冪運算 |
<< | 左位移 |
>> | 右位移 |
& | 位布爾和 |
| | 位布爾或 |
&& | 邏輯和 |
|| | 邏輯或 |
var1=10
if (($var1**2>90))
then
((var2=$var1*2))