wiki:wade/linux/bash

Version 14 (modified by wade, 14 years ago) (diff)

--

source

man bash
#!/bin/bash

符號

`要執行的命令`
`mount | grep "update"`

會執行 中的命令

a=$(tail -n 1 tmp)

會將 tmp 中最後一行的值存入 a 變數內。

判斷式

0 表示正確。 1 表示錯誤。

a=11
test $a -lt 10
echo $?
a=$((a+1))
echo $a

function

function add()
{
echo $1
echo $2
}
add 2 4

dmesg

unset

將變數內容清除

b=12
echo $b
unset b
echo $b

sed

sed 's/要被取代的字串/新的字串/g'

awk

以空白將字串分開,第一個字串代表 $1 ,第二個字串代表 $2

dmesg | tail -n 1 | awk '{print $2}'

read

read aa < "tmp"

將 tmp 檔內的資料讀入 aa 內。

whiptail

產生對話式選單

whiptail --menu "test" 0 0 0 a1 "test a1" a2 "test a2"

做一個選單,test a1 選項結果為 a1, test a2 選項結果為 a2

whiptail --menu "test" 0 0 0 a1 "test a1" a2 "test a2" 2> tmp

將結果標準錯誤輸出至 tmp 內

使用 LWP 撰寫模擬 http/https 互動程式

使用 expect 撰寫模擬 telnet/ssh 互動程式