linux中shell腳本的執(zhí)行通常有4種方式,分別為工作目錄執(zhí)行,絕對路徑執(zhí)行,sh執(zhí)行,shell環(huán)境執(zhí)行。
首先,看下我們的腳本內(nèi)容
[tan@tan?scripts]$?ll total?4 -rw-rw-r--.?1?tan?tan?68?May?8?23:18?test.sh [tan@tan?scripts]$?cat?test.sh? #!/usr/bin/bash ? /usr/bin/python?<p>(推薦教程:<a href="https://www.php.cn/linux.html" target="_blank">linux教程</a>)</p><p>1、工作目錄執(zhí)行</p><p>工作目錄執(zhí)行,指的是執(zhí)行腳本時,先進(jìn)入到腳本所在的目錄(此時,稱為工作目錄),然后使用 ./腳本方式執(zhí)行</p><pre class="brush:php;toolbar:false">[tan@tan?scripts]$?./test.sh -bash:?./test.sh:?Permission?denied [tan@tan?scripts]$?chmod?764?test.sh [tan@tan?scripts]$?./test.sh Hello?Shell
報了權(quán)限錯誤,這里需要賦權(quán),使用chmod 764 test.sh 賦權(quán)后就可以正常執(zhí)行了。
2、絕對路徑執(zhí)行
絕對路徑中執(zhí)行,指的是直接從根目錄/到腳本目錄的絕對路徑
[tan@tan?scripts]$?pwd /home/tan/scripts [tan@tan?scripts]$?`pwd`/test.sh? Hello?Shell [tan@tan?scripts]$?/home/tan/scripts/test.sh? Hello?Shell
3、sh執(zhí)行
sh執(zhí)行,指的是用腳本對應(yīng)的sh或bash來接著腳本執(zhí)行
[tan@tan?scripts]$?sh?test.sh? Hello?Shell [tan@tan?scripts]$?bash?test.sh? Hello?Shell
4、shell環(huán)境執(zhí)行
shell環(huán)境執(zhí)行,指的是在當(dāng)前的shell環(huán)境中執(zhí)行,可以使用 . 接腳本 或 source 接腳本
[tan@tan?scripts]$?.?test.sh? Hello?Shell [tan@tan?scripts]$?source?test.sh? Hello?Shell
相關(guān)教程推薦:linux教程
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載。
THE END
喜歡就支持一下吧
相關(guān)推薦