精品丰满熟女一区二区三区_五月天亚洲欧美综合网_亚洲青青青在线观看_国产一区二区精选

  • <menu id="29e66"></menu>

    <bdo id="29e66"><mark id="29e66"><legend id="29e66"></legend></mark></bdo>

  • <pre id="29e66"><tt id="29e66"><rt id="29e66"></rt></tt></pre>

      <label id="29e66"></label><address id="29e66"><mark id="29e66"><strike id="29e66"></strike></mark></address>
      學(xué)習(xí)啦 > 學(xué)習(xí)電腦 > 操作系統(tǒng) > Linux教程 > linux中的source命令

      linux中的source命令

      時間: 佳洲1085 分享

      linux中的source命令

        Linux系統(tǒng)中的source命令其實(shí)是個點(diǎn)命令,那么它的具體用法是怎樣的呢?下面由學(xué)習(xí)啦小編為大家整理了linux中的source命令的相關(guān)知識,希望對大家有幫助!

        linux中的source命令詳解

        通常用法:source filepath 或 . filepath

        功能:使當(dāng)前shell讀入路徑為filepath的shell文件并依次執(zhí)行文件中的所有語句,通常用于重新執(zhí)行剛修改的初始化文件,使之立即生效,而不必注銷并重新登錄。例如,當(dāng)我們修改了/etc/profile文件,并想讓它立刻生效,而不用重新登錄,就可以使用source命令,如source /etc/profile。

        source命令(從 C Shell 而來)是bash shell的內(nèi)置命令;點(diǎn)命令(.),就是個點(diǎn)符號(從Bourne Shell而來)是source的另一名稱。這從用法中也能看出來。

        擴(kuò)展:source filepath 與 sh filepath 、./filepath的區(qū)別

        當(dāng)shell腳本具有可執(zhí)行權(quán)限時,用sh filepath與./filepath是沒有區(qū)別的。./filepath是因?yàn)楫?dāng)前目錄沒有在PATH中,所有"."是用來表示當(dāng)前目錄的。

        sh filepath 會重新建立一個子shell,在子shell中執(zhí)行腳本里面的語句,該子shell繼承父shell的環(huán)境變量,但子shell是新建的,其改變的變量不會被帶回父shell,除非使用export。

        source filename其實(shí)只是簡單地讀取腳本里面的語句依次在當(dāng)前shell里面執(zhí)行,沒有建立新的子shell。那么腳本里面所有新建、改變變量的語句都會保存在當(dāng)前shell里面。

        舉例說明:

        新建一個test.sh腳本,內(nèi)容為:A=1;

        修改其可執(zhí)行權(quán)限:chmod +x test.sh;

        運(yùn)行sh test.sh后,echo $A,顯示為空,因?yàn)锳=1并未傳回給當(dāng)前shell;

        運(yùn)行./test.sh后,也是一樣的效果;

        運(yùn)行source test.sh 或者 . test.sh,然后echo $A,則會顯示1,說明A=1的變量在當(dāng)前shell中;

      3626283