本教程操作環(huán)境:linux7.3系統(tǒng)、Dell G3電腦。
創(chuàng)建文件
vi test.txt# 按i切換insert模式# 輸入文本#!/bin/bashecho "Hello world!?。?echo $$ # 打印當(dāng)前進(jìn)程idecho $test
執(zhí)行(運(yùn)行)文件的方式
(相關(guān)資料圖)
1、 使用source執(zhí)行腳本
test=100source test.txt
輸出:
Hello world!!!37790100
使用的為當(dāng)前bash
2、 使用.執(zhí)行腳本
. test.txt Hello world!!!37790100
使用的為當(dāng)前bash
3、 使用bash執(zhí)行腳本
bash test.txt Hello world!!!47733
進(jìn)程id更新了,且未獲取到變量test的值,因?yàn)閱?dòng)了子進(jìn)程的bash執(zhí)行腳本。
4、 使用./file執(zhí)行腳本
注意:此種方式首先得給腳本添加執(zhí)行權(quán)限 chmod +x test.txt
./test.txt Hello world!!!47758
進(jìn)程id更新了,且未獲取到變量test的值,因?yàn)閱?dòng)了子進(jìn)程的bash執(zhí)行腳本。
推薦學(xué)習(xí):Linux視頻教程
以上就是linux運(yùn)行文件命令有哪些的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!
關(guān)鍵詞: linux