差異處
這裏顯示兩個版本的差異處。
linux:shell_script [2016/07/02 11:01] tony |
linux:shell_script [2023/06/25 09:48] |
||
---|---|---|---|
行 1: | 行 1: | ||
- | {{tag>Linux ShellScript}} | ||
- | ====== Shell Script ====== | ||
- | ShellScript有多強大我不必贅述。我所撰寫的文章都是以前遇到問題所想到的解決方法,也許不是每個做法都很完美,畢竟都是遇到的東西越多,才越能學習到更多更精闢的語法。 | ||
- | ===== Article List ===== | ||
- | * [[.sell_script:sh_power_on_off_vm|如何透過Shellscript去開啟與關閉你的VM?]] | ||
- | * [[.sell_script:sh_kill_proc|如何給予一個關鍵字去砍掉對應的Process?]] | ||
- | * [[.sell_script:searchPort|找尋被佔用的Port]] | ||
- | * [[.sell_script:replaceFiles|替換檔案]] | ||
- | * [[.sell_script:process_time|Process Time]] | ||
- | * [[.shell_script:setupAutologin|AutoLogin]] | ||
- | * [[.shell_script:replaceString|字串取代]] | ||
- | * [[.shell_script:searchPortFromProcess|如何由PID去找它所佔用的port?]] | ||
- | * [[.shell_script:rebindAllSCSI|Rebind所有的SCSI hard drive]] | ||
- | * [[.shell_script:nc|nc - netcat]] | ||
- | * [[.shell_script:get_local_ip|取得IP Address]] included ipv4, ipv6 and cable status | ||
- | * [[.shell_script:execution_time_measurement|測量執行時間]] | ||
- | ===== 暫存區 ===== | ||
- | ==== grep space ==== | ||
- | 並非所有系統grep都支援\s去偵測空白,可以使用[:space:]或[:blank:]當替代方案。(實測SLES11 grep 2.5.1不支援\s寫法) | ||
- | * [[http://unix.stackexchange.com/questions/81916/how-to-find-a-space-in-a-text-using-grep|how-to-find-a-space-in-a-text-using-grep?]] | ||
- | * [[http://linux.vbird.org/linux_basic/0330regularex.php|鳥哥 - 正規表示法與文件格式化處理]] | ||
- | ==== 確認行數 ==== | ||
- | 代表有15行。 | ||
- | <code bash> | ||
- | > lspci | awk '{ print NR }' | ||
- | 1 | ||
- | 2 | ||
- | .. | ||
- | 15 | ||
- | </code> | ||
- | ==== Assign指令結果至變數 ==== | ||
- | 使用`號去包起來,以下範例會顯示123。 | ||
- | <code bash> | ||
- | VAR=`echo 123` | ||
- | echo $VAR | ||
- | </code> | ||
- | 假如指令有問題也要一併導至VAR,可以透過將stderr導向stdout: | ||
- | <code bash> | ||
- | VAR=`ff 2>&1` | ||
- | echo $VAR | ||
- | </code> | ||
- | |||
- | |||
- | ===== Reference ===== | ||
- | * [[http://bbs.chinaunix.net/thread-452942-1-1.html|Shell基礎12篇]] | ||
- | * [[http://bbs.chinaunix.net/thread-218853-1-1.html|Shell 13問]] | ||
- | * [[http://stackoverflow.com/questions/3701809/how-to-detect-using-of-wildcard-asterisk-as-parameter-for-shell-script|看起來可以解決傳遞*參數問題]] 待試.. | ||
- | * [[http://www.21andy.com/blog/20071121/677.html|nohup]] | ||
- | * [[http://stackoverflow.com/questions/8742783/returning-value-from-called-function-in-shell-script|Function Call Return Value的三種方式]] | ||
- | * [[http://www.jz123.cn/text/1633374.html|解決在Windows上修改後,跳行的問題]] | ||
- | * [[http://www.cyut.edu.tw/~dywang/linuxProgram/node20.html|awk工具]] | ||
- | * [[http://shabirimam.wordpress.com/2009/03/10/adding-script-to-run-at-startup-or-shutdown/|adding-script-to-run-at-startup-or-shutdown]] | ||
- | * [[http://stackoverflow.com/questions/314675/how-do-i-redirect-the-output-of-an-entire-shell-script-within-the-script-itself|Redirect the output of an entire shell script]] | ||
- | * [[http://mark528.pixnet.net/blog/post/7267334-shell-script%3A-%E6%8E%A7%E5%88%B6%E6%96%87%E5%AD%97%E9%A1%8F%E8%89%B2|控制文字顏色]] | ||
- | * [[http://stackoverflow.com/questions/11952854/how-to-check-if-the-variable-value-in-awk-script-is-null-or-empty|awk處理空字串]] | ||
- | * [[http://www.thegeekstuff.com/2010/07/perl-tcp-udp-socket-programming/|Perl - How To: Perl TCP / UDP Socket Programming using IO::Socket::INET?]] | ||
- | * [[http://unix.stackexchange.com/questions/140750/generate-random-numbers-in-specific-range|Gen Random value]] | ||
- | * [[http://unix.stackexchange.com/questions/178899/optimizing-logical-sector-size-for-physical-sector-size-4096-hdd|取得HD sector資訊的command]] (應還有smartctl) | ||
- | * [[http://unix.stackexchange.com/questions/88281/method-to-check-connectivity-to-other-server|how to test connection?]] |