在 shell 偵測signal很簡單,就是trap。
用法為: trap [command/function] sig1 sig2 ...
比如說:
#!/bin/bash
trap 'echo "got ctrl+c (SIGINT)"' 2
echo "Wait for SIGINT..."
sleep 10
如果在shell執行期間,不想被ctrl+c 中斷,也可以disable:
kezeodsnx 發表在 痞客邦 留言(0) 人氣(2,200)
還是在.bashrc
需求是: 希望在一般user和root的提示符號顏色不同,並且不要提示一大串user@ubuntu等hostname什麼的。
1. unmark "force_color_prompt=yes"
2.
kezeodsnx 發表在 痞客邦 留言(0) 人氣(2,336)
來源: H's 手札
讓 prompt 變彩色:
編輯 ~/.bashrc ,找到"#force_color_prompt=yes"後,將開頭的 # 字號刪除解除註解。
kezeodsnx 發表在 痞客邦 留言(0) 人氣(319)
[轉載請註明出處] http://kezeodsnx.pixnet.net/blog
作者: kezeodsnx
引言
常覺得某些人總是總不好某些事嗎?為什麼高鐵可以虧這麼多錢?每個月繳那麼多健保費,一年也沒看幾次醫生,卻只看到天文數字的健保黑洞。每次要坐火車,總擔心買不到票,也不見什麼時候看過台鐵賺錢的新聞。是不為也還是不能也?
kezeodsnx 發表在 痞客邦 留言(1) 人氣(37,761)
常用vim的話,或多或少會不小在行末多按了幾個空白,或是在檔尾多了幾個空行。作者Vigil寫了一個去除這些東西的function:
" Remove trailing whitespace when writing a buffer, but not for diff files.
" From: Vigil
function RemoveTrailingWhitespace()
if &ft != "diff"
let b:curcol = col(".")
let b:curline = line(".")
silent! %s/\s\+$//
silent! %s/\(\s*\n\)\+\%$//
call cursor(b:curline, b:curcol)
endif
endfunction
autocmd BufWritePre * call RemoveTrailingWhitespace()
將這個function加入/etc/vim/vimrc即可。試用了一下,真不錯~感謝Vigil.
kezeodsnx 發表在 痞客邦 留言(1) 人氣(876)
在COdE fr3@k的部落格,看到了他有趣的連絡方式,我也來學一下~
echo lw.lv@vhfuhw | tr d-zabc.@ a-z@.
真有趣~tr用了這麼久,還是第一次這樣用~
kezeodsnx 發表在 痞客邦 留言(0) 人氣(173)
[轉載請註明出處] http://kezeodsnx.pixnet.net/blog
作者: kezeodsnx
每個cmd都需要stdin, stdout, stderr,正常情況下,cmd從stdin (keyboard)讀資料,輸入結果到stdout (monitor),輸出錯誤到stderr (monitor)。如果這3個file descriptor有問題,就會出現以下情形: 先把stdout 關掉,再下ls:
user@user-ubuntu:~$ exec >&-
user@user-ubuntu:~$ ls
ls: write error: Bad file descriptor
kezeodsnx 發表在 痞客邦 留言(0) 人氣(13,433)
[轉載請註明出處] http://kezeodsnx.pixnet.net/blog
作者: kezeodsnx
在Shell script中,所有的cmd是依序執行的。有時候,可能需要某幾個cmd為一組,要嘛都run,要嘛都不run,此時,command group就派上用場了。有兩種使用方式:()和{},其差異為前者是使用subsell (nested subshell),意即會開新的shell來執行command group,在此subshell所做的改變不影響原shell。後者是在同一個shell (no-named command group),因此share相同的shell environment。
舉個例:
kezeodsnx 發表在 痞客邦 留言(0) 人氣(359)