此頁面的樣式無法正確顯示
您所選擇的模板與CSS樣式內容不相容,建議您至管理後台更換模板,或套用其他樣式。
This page looks plain and unstyled
The template you're using is not compatible with your CSS theme. Please change your template or apply other CSS theme to fix it.

My life,my experience...
   喜歡一種 自由自在 無拘無束的感覺
Album | Blog | Comment | Profile | Control Panel
fvalinux | 19 March,2009 1:40

bash之命令執行的順序

一般來說,在shell提示符號下輸入的指令再按下enter後
系統會依以下的順序來找到命令再去執行,執行完成即結束

1.以絕對(相對)路徑表示的命令
e.g.,
$ /bin/ls

2.以alias別名裡有設定的名稱
e.g.,
$ alias
alias mv='mv -i'
alias rm='rm -i'
alias cp='cp -i'
alias telnet='/usr/bin/telnet-ssl -8'

3.在function裡有定義的函數名稱
e.g.,
(定義一個function,名稱CatPasswd)
$ CatPasswd (){ cat /etc/passwd; }
$ CatPasswd | head -n1
root:x:0:0:root:/root:/bin/bash

4.在shell裡面的內建命令
e.g.,
$ cd
$ exit
$ type
(可以用type這個builtin command來判斷)
$ type cd
cd is a shell builtin
$ type exit
exit is a shell builtin
$ type echo
echo is a shell builtin
(其實echo指令有內建命令和外部命令兩種)
(要執行外部命令的echo要用明確路徑/bin/echo的方式)

5.PATH環境變數裡指定的路徑
就是你打echo $PATH命令所顯示出來的那些路徑啦
當你打的命令在上面4個都找不到的情況下,就會往這些path路徑裡找

最後,如果bash都找不到的話,就會跟你說command not found



Comment

不過我今天在看
《bash shell入門 第三版》
ISBN: 986-7794-59-1
這本oreilly的書第306頁時,裡面提到有些shell內建變數
的執行順序會優於function
像break、exit、exec、continue等等
都會優先於函式,但是呢,經過我的測試,
先定義一些這些名稱的function再去執行,還是function優先啊
奇怪,難不成我被oreilly擺了一道?

pixnet user  fvalinux  |  19/03/2009 02:13:25

喜歡你的部落格,讓人流連忘返

yumiko  |  13/12/2009 09:04:35

請點U左上方F小房子C看看喔

歡迎s大家c來看看

好玩唷  |  15/12/2009 00:10:57

Trackback

Comment Permissions: Allow commenting

Leave Comment

*Name/Nickname
E-mail
Personal Website
Comment Title
*Comment
* Private Comment