Shell 常用的語句整理

2021-09-14 00:11:51 字數 1017 閱讀 7879

1、字串的拼接

name=

'tom'

;"my name is $"

2、格式化時間

$ echo

$(date

"+%y-%m-%d %h:%m:%s"

)2019-03-28 19:54:31

3、命令列引數

$#  # 命令列的引數數量

$1$2

$n# 位置引數

$0# 代表了指令碼的名字

4、if 語句結構

if

;then

echo

else

echo

fi

5、退出當前shell

$ exit 0

0表示成功(zero - success)

非0表示失敗(non-zero - failure)

2表示用法不當(incorrect usage)

127表示命令沒有找到(command not found)

126表示不是可執行的(not an executable)

>=128 訊號產生

6、檔案判斷

-e filename 存在

-d filename 目錄

-f filename 常規檔案

-l filename 符號鏈結

-r filename 可讀

-w filename 可寫

-x filename 可執行

-s filename 檔案長度不為0

-h filename 檔案是軟鏈結

參考

shell中判斷檔案,目錄是否存在

shell指令碼中判斷輸入引數個數的方法

linux命令之exit - 退出當前shell【返回值狀態】

shell中常用的語句

for num in 1 2 3 for num in for num inseq 1 3或者 for num inseq 1 2 10 do done for語句示例 for name in westos linux 666 do echo name done while 條件 do done w...

常用sql語句整理

a 判斷資料庫是否存在 if exists select from sys.databases where name 庫名 刪除資料庫 drop database 庫名b 判斷要建立的表名是否存在 if exists select from dbo.sysobjects where id objec...

常用SQL語句整理

檢視資料庫 show databases 選擇資料庫 use database name 表定義資訊 describe table name 插入資料 insert into table name filed 1 field n values value 1 value n eg insert in...