linux之shell指令碼

2021-10-08 10:52:45 字數 1716 閱讀 8484

shell 是指一種應用程式,這個應用程式提供了乙個介面,使用者通過這個介面訪問作業系統核心的服務,是指令碼中命令的直譯器。

1、記錄命令執行的過程和執行邏輯,以便以後重複執行;

2、指令碼可以批量處理主機;

3、指令碼可以定時處理主機。

#!/bin/bash           #幻數

#指令碼執行的直譯器,最優先執行

vim自動新增指令碼首部

vim /etc/vimrc

"map

ms:call westostitle(

)'s # 手動新增,按f4增加首部

autocmd bufnewfile *

.sh,

*.script call westostitle(

)# 自動新增,針對新檔案、.sh或.script結尾的檔案自動新增首部## mytitle函式體,即自動新增部分

func westostitle()0

,"#########################")1

,"# author: lee")2

,"# version: ")3

,"# create_time: ")4

,"# mail: ")5

,"# info: ")6

,"# ")7

,"#########################")8

,"")9

,"#!/bin/bash"

)endfunc

sh script.sh
source script.sh或.script.sh
chmod +x script.sh

/***x/***x/script.sh

./script.sh

sh -x /mnt/dsd.sh

+#表示執行指令

不帶+#表示命令執行的輸出

#!/bin/bash

ifconfig "$1"

| awk '/inet\>/'

hostname

#!/bin/bash

echo "hostname: `hostname`"

ifconfig `nmcli device status | awk '$2~/ethernet/'` | awk '/inet\>/'

ehco 「ipaddress: 『ifconfig br0 | awk 『/inet\>

/』』」

echo "username: `whoami`"

cat /etc/sysconfig/rsyslog ## 查詢日誌檔案
#!/bin/bash

["`whoami`"

="root"]|

|for log_name in $(awk '/./&&!/^#/&&!/^\$/&&$2~/^\/|^\-/'

/etc/rsyslog.conf | sed 's/-//g'

)do

> $log_name &&

done

Linux之shell指令碼

1.shell是系統的使用者介面,提供了使用者與核心進行互動操作的一種介面。它接收使用者輸入的命令並把它送入核心去執行。2.每個linux系統的使用者可以擁有他自己的使用者介面或shell,用以滿足他們自己專門的shell需要。同linux本身一樣,shell也有多種不同的版本 比如bash或sh ...

shell指令碼 複數 linux之shell指令碼

1 如何向指令碼傳遞引數 script argument 例子 顯示檔名稱指令碼 2 如何在指令碼中使用引數 第乙個引數 1,第二個引數 2 例子 指令碼會複製檔案 arg1 到目標位址 arg2 3 如何計算傳遞進來的引數 4 如何在指令碼中獲取指令碼名稱 05 如何檢查之前的命令是否執行成功 6...

Linux學習之shell指令碼

第一行 bin bash 標記指令碼的直譯器 指令碼 bin bash echo hello world 賦予執行許可權 chmod x test.sh 執行指令碼 test.sh 定義變數時不需要 符號 td date y m d 1.變數名和符號之間不能有空格 2.首個字元必須為字母 3.中間不...