為增加**復用性,建立函式
函式1, func1.sh
同一指令碼內呼叫
#!/bin/bash
#定義變數
user=aaa;
display()
display
source func1.sh 到入庫 或者 . func1.sh
函式2,func2.sh
跨指令碼呼叫
#!/bin/bash
#引入外部指令碼 使用source有時出錯 使用". "代替 注意後面空格
. func1.sh
display
有引數輸入函式 plus.sh
#!/bin/bash
#定義變數
plus()
#plus 12 23
source plus
plus 12 23
輸出 35
檢視當前系統內匯入的函式
set命令
LINUX 指令碼編寫
練習 1.編寫指令碼 bin per.sh,判斷當前使用者對指定的引數檔案,是否不可讀並且不可寫 指令碼內容如下 echo 請輸入需要檢視的檔案路徑 read file path a 1b 1 cat file path dev null a echo touch file path dev nul...
linux指令碼編寫記錄
1.重啟某個埠,適用於如tomcat重啟8080埠,根據lsof命令查出,通過grep獲取指定行,awk獲取到指定列進而得出pid值關閉即可.pid lsof i 3001 grep v pid grep w listen awk echo pid if pid then kill 9 pid ec...
Linux 指令碼編寫基礎 四
4 函式 如果您寫了一些稍微複雜一些的程式,您就會發現在程式中可能在幾個地方使用了相同的 並且您也會發現,如果我們使用了函式,會方便很多。乙個函式是這個樣子的 functionname inside the body 1 is the first argument given to the func...