PIXNET Logo登入

心的距離

跳到主文

Google
Custom Search

部落格全站分類:數位生活

  • 相簿
  • 部落格
  • 留言
  • 名片
  • 12月 08 週三 201009:58
  • trap sigal in shell

在 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)

  • 個人分類:Shell
▲top
  • 8月 04 週二 200915:25
  • 改變shell prompt

還是在.bashrc
需求是: 希望在一般user和root的提示符號顏色不同,並且不要提示一大串user@ubuntu等hostname什麼的。
1. unmark "force_color_prompt=yes"
2.
(繼續閱讀...)
文章標籤

kezeodsnx 發表在 痞客邦 留言(0) 人氣(2,336)

  • 個人分類:Shell
▲top
  • 7月 29 週三 200912:55
  • [轉貼] 讓Linux變彩色的: prompt, man 彩色化

來源: H's 手札
讓 prompt 變彩色:
編輯 ~/.bashrc ,找到"#force_color_prompt=yes"後,將開頭的 # 字號刪除解除註解。
(繼續閱讀...)
文章標籤

kezeodsnx 發表在 痞客邦 留言(0) 人氣(319)

  • 個人分類:Shell
▲top
  • 6月 24 週三 200915:20
  • 換人做做看--sudo 和 su

[轉載請註明出處] http://kezeodsnx.pixnet.net/blog
作者: kezeodsnx
引言
常覺得某些人總是總不好某些事嗎?為什麼高鐵可以虧這麼多錢?每個月繳那麼多健保費,一年也沒看幾次醫生,卻只看到天文數字的健保黑洞。每次要坐火車,總擔心買不到票,也不見什麼時候看過台鐵賺錢的新聞。是不為也還是不能也?
(繼續閱讀...)
文章標籤

kezeodsnx 發表在 痞客邦 留言(1) 人氣(37,761)

  • 個人分類:Shell
▲top
  • 6月 05 週五 200916:24
  • vim自動去除行末空白及最後的空白行

常用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)

  • 個人分類:Shell
▲top
  • 6月 05 週五 200916:12
  • 好玩的字串代換

在COdE fr3@k的部落格,看到了他有趣的連絡方式,我也來學一下~
 echo lw.lv@vhfuhw | tr d-zabc.@ a-z@.
真有趣~tr用了這麼久,還是第一次這樣用~
(繼續閱讀...)
文章標籤

kezeodsnx 發表在 痞客邦 留言(0) 人氣(173)

  • 個人分類:Shell
▲top
  • 5月 27 週三 200915:35
  • Linux Shell I/O redirect

[轉載請註明出處] 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)

  • 個人分類:Shell
▲top
  • 5月 27 週三 200914:55
  • Command group

[轉載請註明出處] 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)

  • 個人分類:Shell
▲top
1

文章搜尋

廣告版面

廣告版面

參觀人氣

  • 本日人氣:
  • 累積人氣:

文章分類

toggle 生活 (4)
  • 高登鐵漢 (7)
  • 英文筆記 (0)
  • 愚蠢上班族 (12)
  • 無病呻吟 (9)
toggle Linux (7)
  • kernel (2)
  • System (45)
  • Shell (8)
  • android (12)
  • C programming (15)
  • Multimedia (10)
  • Driver (27)
  • server (2)
  • wireless (7)
  • 有的沒的 (3)
  • 未分類文章 (1)

google analytics