顯示具有 sh / bash 標籤的文章。 顯示所有文章
顯示具有 sh / bash 標籤的文章。 顯示所有文章

2014年10月25日 星期六

shell script callback function

myfunc() {
    str=$1

    echo $str
}

callback_handler="myfunc"                                                                                                                  

if [ "$callbak_handler" != "" ]; then
    eval $file_handler asdfghjkl
fi




References :
Friends don't let friends program in shell script | TurnKey GNU/Linux Blog

2014年10月24日 星期五

shell script handle signal

my_signal_handler() {
    echo '....'
}

trap 'my_signal_handler' EXIT HUP TERM INT




References :
Work the Shell - Dealing with Signals | Linux Journal

shell script kill subprocess when exit

jobs=()
trap '((${#jobs[@]} == 0)) || kill ${jobs[*]} ; exit' EXIT HUP TERM INT
subscript1 & jobs+=($!)
subscript2 & jobs+=($!)
 
 
 
 
References :
zsh - Killing subprocesses after the script has finished or is killed - Unix & Linux Stack Exchange

append value to bash array

ARR=()
ARR+=(1)
ARR+=(2)




References :
Bash: add value to array without specifying a key - Stack Overflow

inotifywait background job pid

jobs=()
(echo "$BASHPID" > pid-file; exec inotifywait -m ...) | while IFS= read -r...
jobs+=(`pid-file`)
 
 
 
 

pipe out to shell script function

References :
Pipe output to function - Bash | Unix Linux Forums | Shell Programming and Scripting

2014年4月6日 星期日

Bash 快捷鍵 shortcuts

Alt + U 遊標後一個單字都改成英文大寫
Alt + l 遊標後一個單字都改成英文小寫
Alt + C 遊標後一個單字改成英文開頭大寫
Alt + . 插入最後一個 history 中的文字

2012年10月2日 星期二