ksh/bash | egrep/awk | 含義 |
---|---|---|
*(exp) | exp* | 存在0個或多個 exp |
+(exp) | exp+ | 存在1個或多個 exp |
?(exp) | exp? | 存在0個或1個 exp |
@(exp1|exp2|...) | exp1|exp2|... | exp1 或 exp2 或… |
!(exp) | (none) | 所有不 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
generate_data | tee >(sort | uniq > sorted_data) # 輸出至管道 | |
>(mail -s 'raw data' joe) # 輸出至 mail 程序 | |
> raw_data # 輸出至檔案 |
愛麗絲 | 巴伯 | |
---|---|---|
步驟 1 | 愛麗絲挑選一個祕密數字,例如3,我們把這個數字標示為 A | 巴伯挑選一個祕密數字,例如 6,我們把這個數字標示為 B |
步驟 2 | 愛麗絲把 3 套進這個單向函數,演算7^A(mod 11) 結果為 2 |
巴伯把 6 套進這個單向函數,演算7^B(mod 11) 結果為 4 |
步驟 3 | 愛麗絲把這個函數值 2 稱為 α 傳送給巴伯 | 巴伯把這個函數值 4 稱為 β 傳給愛麗絲 |
步驟 4 | 愛麗絲用巴伯求出的函數值來演算β^A(mod 11) 的結果為 9 |
巴伯用愛麗絲所求出的函數值來演算α^B(mod 11) 的結果為 9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh - | |
echo 'Select your terminal type:' | |
PS3='terminal? ' | |
select term in \ | |
'Givalt GL35a' \ | |
'Tsoris T-2000' \ | |
'Shande 531' | |
do | |
# 使用 case 語句來指定正確的值給 TERM 變量 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh - | |
# 顯示用戶活動中的進程數與進程名稱 | |
# 可篩選特定用戶(egrep) | |
# | |
# | |
# 語法: | |
# puser [ user1 user2 ... ] | |
IFS=' | |
' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh - | |
# 持續執行 ps 命令 | |
# 每次執行之間,只做短時間的暫停 | |
IFS=' | |
' | |
# 先取得 BSD 版本的 ps | |
PATH=usr/ucb:/usr/bin:/bin | |
export PATH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh - | |
# 根據 MD5 的校驗和顯示在某種程度上內容一致的文件名 | |
IFS=' | |
' | |
PATH=/usr/local/bin:/usr/bin:/bin | |
export PATH | |
md5sum "$@" /dev/null 2> /dev/null | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh - | |
# 尋找所有文件及目錄 | |
# 在目錄樹下,將最近修改過得文件加以組合 | |
# 並於最上層的 FILES.* 與 DIRECTORIES.* 內建立列表 | |
# | |
# 語法: | |
# filesdirectories directory | |
IFS=' | |
' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
def traversal(node): | |
visisted = {node} | |
q = deque([node]) | |
while q: # O(V) | |
current = self.queue.popleft() | |
yield current |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ctypes | |
class DynamicArray(object): | |
''' | |
DYNAMIC ARRAY CLASS (Similar to Python List) | |
''' | |
def __init__(self): | |
self.n = 0 # Count actual elements (Default is 0) |