溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

shell中bash、sh、./、source的示例分析

發布時間:2021-09-10 17:29:31 來源:億速云 閱讀:146 作者:小新 欄目:大數據

這篇文章主要介紹shell中bash、sh、./、source的示例分析,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

  1. sh 和 bash

GNU/Linux 操作系統中的 /bin/sh 本是 bash (Bourne-Again Shell) 的符號鏈接,但鑒于 bash 過于復雜,有人把 bash 從 NetBSD 移植到 Linux 并更名為 dash (Debian Almquist Shell),并建議將 /bin/sh 指向它,以獲得更快的腳本執行速度。Dash Shell 比 Bash Shell 小的多,符合POSIX標準。

1. ubuntu
Linux localhost 4.4.0-105-generic #128-Ubuntu SMP Thu Dec 14 12:42:11 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
xhx@localhost:~$ ls -la /bin/sh
lrwxrwxrwx 1 root root 4 Aug 17  2017 /bin/sh -> dash
2. centos
[root@xuhx-02 bin]# uname -a
Linux xuhx-02 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
[root@xuhx-02 bin]# ls -la sh
lrwxrwxrwx. 1 root root 4 6月  25 16:52 sh -> bash
  1. sh/bash 和 source

  • sh/bash 是打開子shel,在子shell 中運行,在子shell 設置的環境變量不會影響到父shell;

  • source 是在當前shell 中運行,因此修改完環境變量需要運行source /etc/profile 使其生效 而不是使用sh/bash命令;source = .;

  • ./ 需要對執行的腳本有r和x權限

[root@xuhx-02 ~]# sh t.sh 
anaconda-ks.cfg  hello  n2n  newdir1  pytho.py  rpmbuild  sort  test.sh  t.sh  ttttt.sh
[root@xuhx-02 ~]# bash t.sh
anaconda-ks.cfg  hello  n2n  newdir1  pytho.py  rpmbuild  sort  test.sh  t.sh  ttttt.sh
[root@xuhx-02 ~]# ./t.sh
-bash: ./t.sh: 權限不夠
[root@xuhx-02 ~]# source t.sh
anaconda-ks.cfg  hello  n2n  newdir1  pytho.py  rpmbuild  sort  test.sh  t.sh  ttttt.sh
[root@xuhx-02 ~]# . t.sh 
anaconda-ks.cfg  hello  n2n  newdir1  pytho.py  rpmbuild  sort  test.sh  t.sh  ttttt.sh

以上是“shell中bash、sh、./、source的示例分析”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女