Ubuntu 进阶(一)shell script主讲:廖凡磊

上传人:jiups****uk12 文档编号:57311602 上传时间:2018-10-20 格式:PPT 页数:71 大小:229.60KB
返回 下载 相关 举报
Ubuntu 进阶(一)shell script主讲:廖凡磊_第1页
第1页 / 共71页
Ubuntu 进阶(一)shell script主讲:廖凡磊_第2页
第2页 / 共71页
Ubuntu 进阶(一)shell script主讲:廖凡磊_第3页
第3页 / 共71页
Ubuntu 进阶(一)shell script主讲:廖凡磊_第4页
第4页 / 共71页
Ubuntu 进阶(一)shell script主讲:廖凡磊_第5页
第5页 / 共71页
点击查看更多>>
资源描述

《Ubuntu 进阶(一)shell script主讲:廖凡磊》由会员分享,可在线阅读,更多相关《Ubuntu 进阶(一)shell script主讲:廖凡磊(71页珍藏版)》请在金锄头文库上搜索。

1、Ubuntu 進階(一) shell script 主講:廖凡磊,國立中央大學電算中心 ubuntu 短期訓練課程,agenda,Shell introduction & features Shell script Q & A,part1:shell introduction and features,為什麼要學習shell呢?,因為他好用.廢話 快速好用的組合命令 分析系統記錄檔的利器 一輩子受用的工具,What is SHELL,the hard protective outer case of an animal such as a snail, shellfish, or turtle

2、(from Oxford) shell is a piece of software that provides an interface for users. (from wikipedia) 橋樑 (from me),登入ubuntu的流程,gettyget terminal(tty) (ctrl+alt+f1-f7) login-authenticate the user shellprovides an interface between user and kernel logout- good bye,程式執行流程,人下命令給shell shell對kernel下命令 kernel對

3、hardware執行工作,並回收結果 kernel回傳給shell shell 顯示出執行結果kernel 又是什麼呢?,key: 其實DOS時代也有shell,就是,kernel,以人來比喻的話,shell就像是語言,shell也是一種ap,各種硬體設備,/etc/shells,/bin/csh (c-like shell) /bin/sh (目前由dash所取代) /bin/ksh (kornshell, by AT&T Bell LAB) /bin/tcsh (enhanced csh, is FreeBSD default login shell) /bin/bash (bourne-

4、again shell, is ubuntu defaul login shell) /bin/dash (debian almquist shell,強調快速及檔案小),操作1:,看目前所使用的shell類型 echo $SHELL cat /etc/passwd /bin/false ? 換shell chsh 注意:請務必打完整的shell位置,不然會很麻煩,如何選擇自己要用的shell,師法於你的朋友們 愛用預設值 BSD default shell -csh/tcsh Linux default shell - sh/bash學習哪一套unix-like OS 也是一樣的,bash

5、的特色,Job control Aliases Shell functions Directory stack Command history Command line editing Vi Command line editing Filename completion,設定你的bash環境,登入: /etc/profile -全域 /.bash_profile - login時用到 /.bash_login - login時用到 /.profile - login時用到 /.bashrc - subshell產生時會用到 登出: /.bash_logout,實用的一些設定 in /.bas

6、hrc,grep 有顏色 alias grep=grep -color man 有顏色export LESS_TERMCAP_mb=$E01;31mexport LESS_TERMCAP_md=$E01;31mexport LESS_TERMCAP_me=$E0mexport LESS_TERMCAP_se=$E0mexport LESS_TERMCAP_so=$E01;44;33mexport LESS_TERMCAP_ue=$E0mexport LESS_TERMCAP_us=$E01;32m,跟嗶嗶聲說不,tab補齊時的嗶嗶聲 in /.inputrc set bell-style no

7、ne #關閉 set bell-style visible #開啟 vim錯誤指令時的嗶嗶聲 in /.vimrc set vb ”關閉 less錯誤時的嗶嗶聲 in /.bashrc alias less=less -Q #關閉所有的錯誤報告,路徑問題,絕對路徑 由 / 開始的路徑 相對路徑 不是用 / 開始的路徑 . #當前的目錄#上一層目錄 #家目錄 等於/home/userName tip: 寫shell script時最好是用絕對路徑 如果查指令的絕對路徑 which command,指令複習,cd mkdir ls ps grep who rm date,指令複習二,pwd cp

8、mv cat less,bash的基本認識,指令運用 工作控制的運用 輸入,輸出資料重導向 管線的觀念與運用 萬用字元的運用 history的設定與運用 別名的設定與運用 引號的觀念及運用 變數的運用 數值運算,指令的運用(1),單一指令 pwd ps -aux netstat -an 連續指令 mkdir /tempDir; cp /.* /tempDir; ls /tempDir,指令的運用(2),條件式指令 grep google sampleCom.txt & more sampleCom.txt grep google sampleCom.txt | echo “no” gcc pr

9、og.c | echo compile error & - it means than,指令1失敗則不會執行後者 | -it means else,指令1成功則不會執行後者 指令類別 內建命令(built-in command) 一般程式(utility) 如果辨別: which command,指令運用(3),指令列的格式 command option arguments ls -al rm -i test.txt echo ”hello world” 遇到問題時 man可靠的男人,man command info command option中 加上-h,-help,command-lin

10、e editing,C-w 往前刪除一個字。 M-f 往前一個字 M-b 往後一個字 C-u 刪除前面所有字元 C-k 刪除後方所有字元 C-l 清除螢幕 C-r 往前搜尋指令 ( 非常好用 ) C-xC-e 可以使用 vim 寫入 script 讓他一次執行。,輸入,輸出重導向, Output Redirection Appending Output Redirection Input Redirection ls ls.out shellncucc cat text.out Shellncucc who ls.out shellncucc cat text.out mail orzorz.

11、orz touch a.c; touch b.c;touch cc.c;mkdir dir1;mkdir dir2 shellncucc ls *.c a.c b.c cc.c shellncucc ls ?.c a.c b.c shellncucc ls ac* a.c b.c shellncucc ls A-Za-z*,history 的運用與設定,history觀看歷史指令 ! 執行上一個指令 !n 執行第n個指令 !string 搜尋以某字串 string為開頭的過去並加以執行 搜尋時以event數字大到小 !?string? 搜尋過去指令中有某個字串的指令,別名設定與運用,設定ali

12、as name=command 解除 unalias name 顯示全部設定 alias 顯示某個設定 alias name 可以在一開始就設定在/.bashrc,alias 好用設定,alias name=command #注意等號兩旁沒空格 alias ls=ls -aF -color=always alias ll=ls -l alias search=grep alias mcd=mount /mnt/cdrom alias ucd=umount /mnt/cdrom alias mc=mc -c alias =cd alias .=cd /,工作控制的運用,什麼是job contro

13、l 前景工作 需等待提示符號出現才能進行下個動作 背景工作 在一般的指令後面加個 & 常用的指令 Ctrl+c 中斷指令 Ctrl+z 放入背景,並暫停其指令 bg %1 讓編號1的工作在背景執行 fg %1 讓編號1的工作在前景執行,工作控制的運用 Ex.,vim hello.sh Ctrl + z 放入背景 fg 跳回去vim編輯介面,引數的觀念及運用,單引號single quote() 兩個單引號中的內容是不變的 雙引號double quote(”) 對自動替換雙引號中的特殊字元 雙數 倒單引號back quote() 會先被執行 如果將倒單引號放在單引號中,會沒有作用,引號的觀念及運用

14、-範例,% color=red % echo “$color” red % echo $color $color % echo “There are who | wc -l people online” There are 1 people online,變數(1),印出變數的內容 echo $HOME echo $PATH 設值 = 等號兩邊不能直接接空白字元; 變數名稱只能是英文字母與數字,但是數字不能是開頭字元;,變數(2),鍵盤讀取變數 read variable read p ”提示字串:” variable echo $variable 陣列 varindex=content ec

15、ho $varindex,變數(3),環境變數 env set export 變數名稱 HOME SHELL HISTSIZE PATH LANG,習題,如何利用last將你今天登入過的資訊印出來如何讓檔案在刪除時會提醒是否真要刪除如何秀出在/bin底下任何以a為開頭的檔案檔名的詳細資料,解答,last | grep account alias rm = rm -i ls al /bin/a*,數值運算,variable=$(1+2) declare -i variable=6/2 let variable=1*2 整數 範例 (i+) 等於 let i+ 等於 i=$(i+1) 等於 i=$($i+1) (C=A+B) 等於 let C=A+B 等於 C=$(A+B) 等於 C=$($A+$B),

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号