• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Welcome to ErranLi's Blog!

              C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              106 Posts :: 1 Stories :: 97 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(12)

            搜索

            •  

            積分與排名

            • 積分 - 174947
            • 排名 - 151

            最新評論

            閱讀排行榜

            bashdash/bin/bash/bin/sh) 

              原文:http://www.cnblogs.com/dkblog/archive/2011/04/02/2003822.html

            Linux中的shell有多種類型,其中最常用的幾種是Bourne   shellsh)、C   shellcsh)和Korn   shellksh)。三種shell各有優缺點。

            Bourne   shellUNIX最初使用的shell,并且在每種UNIX上都可以使用。Bourne   shellshell編程方面相當優秀,但在處理與用戶的交互方面做得不如其他幾種shell

            Linux操作系統缺省的shellBourne   Again   shell,它是Bourne   shell的擴展,簡稱Bash,與Bourne   shell完全向后兼容,并且在Bourne   shell的基礎上增加、增強了很多特性。Bash放在/bin/bash中,它有許多特色,可以提供如命令補全、命令編輯和命令歷史表等功能,它還包含了很多C   shellKorn   shell中的優點,有靈活和強大的編程接口,同時又有很友好的用戶界面。

            GNU/Linux 操作系統中的 /bin/sh 是 bashBourne-Again Shell)的符號鏈接,

                但鑒于 bash 過于復雜,有人把 ash 從 NetBSD 移植到 Linux 并更名為 dashDebian Almquist Shell),并建議將 /bin/sh 指向它,以獲得更快的腳本執行速度。Ubuntu 號稱自從他們在 6.10 版里這樣做了以后,系統啟動速度有了明顯的提升。Debian 計劃在下一個發行版(代號 lenny)中也將 dash 作為默認的 /bin/sh


            /bin/sh與/bin/bash的細微區別

            原文:不詳

            在shell腳本的開頭往往有一句話來定義使用哪種sh解釋器來解釋腳本。
            目前研發送測的shell腳本中主要有以下兩種方式:
            (1) #!/bin/sh
            (2) #!/bin/bash
            在這里求教同福客棧的各位大俠們一個問題:
            以上兩種方式有什么區別?對于腳本的實際運行會產生什么不同的影響嗎?

            腳本test.sh內容:
            #!/bin/sh
            source pcy.sh #pcy.sh并不存在
            echo hello
            執行./test.sh,屏幕輸出為:
            ./test.sh: line 2: pcy.sh: No such file or directory
            由此可見,在#!/bin/sh的情況下,source不成功,不會運行source后面的代碼。
            修改test.sh腳本的第一行,變為#!/bin/bash,再次執行./test.sh,屏幕輸出為:
            ./test.sh: line 2: pcy.sh: No such file or directory
            hello
            由此可見,在#!/bin/bash的情況下,雖然source不成功,但是還是運行了source后面的echo語句。
            但是緊接著我又試著運行了一下sh ./test.sh,這次屏幕輸出為:
            ./test.sh: line 2: pcy.sh: No such file or directory
            表示雖然腳本中指定了#!/bin/bash,但是如果使用sh 方式運行,如果source不成功,也不會運行source后面的代碼。

            為什么會有這樣的區別呢?

            junru同學作了解釋

            1. sh一般設成bash的軟鏈
            [work@zjm-testing-app46 cy]$ ll /bin/sh
            lrwxrwxrwx 1 root root 4 Nov 13 2006 /bin/sh -> bash
            2. 在一般的linux系統當中(如redhat),使用sh調用執行腳本相當于打開了bash的POSIX標準模式
            3. 也就是說 /bin/sh 相當于 /bin/bash --posix

            所以,sh跟bash的區別,實際上就是bash有沒有開啟posix模式的區別

            so,可以預想的是,如果第一行寫成 #!/bin/bash --posix,那么腳本執行效果跟#!/bin/sh是一樣的(遵循posix的特定規范,有可能就包括這樣的規范:“當某行代碼出錯時,不繼續往下解釋”)


            例如:
            [root@localhost yuhj]# head -n1 x.sh
            #!/bin/sh
            [root@localhost yuhj]# ./x.sh

            ./x.sh: line 8: syntax error near unexpected token `<'
            ./x.sh: line 8: ` while read line; do { echo $line;((Lines++)); } ; done < <(route -n)'
            [root@localhost yuhj]#



            [root@localhost yuhj]# head -n1 x.sh
            #!/bin/bash
            [root@localhost yuhj]#./x.sh

            Kernel IP routing table
            Destination Gateway Genmask Flags Metric Ref Use Iface
            192.168.202.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
            0.0.0.0 192.168.202.2 0.0.0.0 UG 0 0 0 eth0
            Number of lines read = 4
            [root@localhost yuhj]#


            [root@localhost yuhj]# head -n1 x.sh
            #!/bin/bash --posix
            [root@localhost yuhj]#
            [root@localhost yuhj]# ./x.sh

            ./x.sh: line 8: syntax error near unexpected token `<'
            ./x.sh: line 8: ` while read line; do { echo $line;((Lines++)); } ; done < <(route -n)'



            [root@localhost yuhj]# whereis sh bash
            sh: /bin/sh /usr/share/man/man1/sh.1.gz /usr/share/man/man1p/sh.1p.gz
            bash: /bin/bash /usr/share/man/man1/bash.1.gz

            [root@localhost yuhj]# ll /bin/sh /bin/bash
            -rwxr-xr-x 1 root root 735004 May 25 2008 /bin/bash
            lrwxrwxrwx 1 root root 4 Jan 29 00:39 /bin/sh -> bash
            [root@localhost yuhj]#



             
            posted on 2012-05-24 16:45 erran 閱讀(3686) 評論(0)  編輯 收藏 引用
            99久久国产综合精品网成人影院 | 免费国产99久久久香蕉| 成人国内精品久久久久影院| 久久99精品久久久久久| 999久久久国产精品| 伊人色综合久久天天网| 精品久久久久久无码专区| 国产高清国内精品福利99久久| 久久99这里只有精品国产| 99久久免费国产精品热| 欧美午夜A∨大片久久| 精品免费久久久久久久| 亚洲国产成人乱码精品女人久久久不卡| 人妻无码精品久久亚瑟影视 | 久久午夜无码鲁丝片午夜精品| 日本亚洲色大成网站WWW久久| 久久久久人妻一区精品色| 久久天天躁狠狠躁夜夜2020老熟妇 | 久久精品国产99国产精品导航 | 亚洲午夜久久久久妓女影院| 亚洲国产精品久久久久婷婷软件| 久久久久av无码免费网| 久久久网中文字幕| 久久免费视频网站| 久久国产乱子伦免费精品| 婷婷久久五月天| 欧美与黑人午夜性猛交久久久 | 狠狠色丁香婷婷久久综合不卡 | 欧美激情一区二区久久久| 久久综合中文字幕| 国产精品18久久久久久vr| 久久亚洲中文字幕精品有坂深雪| 一本久久综合亚洲鲁鲁五月天| 久久精品国产精品亚洲| 国产午夜精品久久久久九九电影| 久久精品国产精品国产精品污| 久久99精品久久久久久久久久| 久久婷婷五月综合色奶水99啪| 少妇久久久久久被弄高潮| 精品永久久福利一区二区| 久久精品亚洲日本波多野结衣|