Shell命令解釋器分類示例詳解
Shell命令解釋器:介于 系統(tǒng)內(nèi)核——>命令解釋器——>外圍應(yīng)用程序:應(yīng)用/命令/服務(wù)
Shell編程:bash編程
1、命令解釋器
bash | 目前應(yīng)用最廣泛的一款命令解釋器,紅帽系列(默認(rèn)),Debain,Unbantu,BASH全稱:Bourne-Again Shell |
dash | 一般Debain/Unbantu系統(tǒng)默認(rèn)的,運行腳本推薦使用bash lidao.sh |
csh,tcsh | 一些unix系統(tǒng)使用 |
zsh | 功能更多,支持更多的插件,可以更好看 |
2、編程語言分類
解析:直接解析型 | shell,python,書寫代碼后,通過對應(yīng)解析器運行 |
編譯:需要編譯后運行 | C,C++ |
解釋型
[root@localhost ~]# vim 1.py [root@localhost ~]# cat 1.py print("hrllo world!") [root@localhost ~]# python 1.py hrllo world!
3、Shell腳本執(zhí)行方式
1通過sh或bash執(zhí)行
[root@localhost shell]# vim 01.exec.way.sh [root@localhost shell]# cat 01.exec.way.sh hostname pwd whoami [root@localhost shell]# sh 01.exec.way.sh localhost.localdomain /root/shell root [root@localhost shell]# bash 01.exec.way.sh localhost.localdomain /root/shell root [root@localhost shell]# ll `which sh bash` -rwxr-xr-x. 1 root root 964544 Apr 10 2018 /usr/bin/bash lrwxrwxrwx. 1 root root 4 Mar 23 05:59 /usr/bin/sh -> bash
2通過source或 . 執(zhí)行
[root@localhost shell]# . 01.exec.way.sh localhost.localdomain /root/shell root [root@localhost shell]# source 01.exec.way.sh localhost.localdomain /root/shell root
3通過絕對路徑或相對路徑執(zhí)行
[root@localhost shell]# ./01.exec.way.sh -bash: ./01.exec.way.sh: Permission denied [root@localhost shell]# chmod +x ./01.exec.way.sh [root@localhost shell]# ls -l total 4 -rwxr-xr-x. 1 root root 21 May 6 01:15 01.exec.way.sh [root@localhost shell]# ./01.exec.way.sh localhost.localdomain /root/shell root
4通過重定向符號運行
[root@localhost shell]# sh < 01.exec.way.sh localhost.localdomain /root/shell root [root@localhost shell]# bash < 01.exec.way.sh localhost.localdomain /root/shell root
4、應(yīng)用場景
應(yīng)用及場景
通過sh或bash執(zhí)行 | 書寫腳本后,最常用的方式,在其他非紅帽系統(tǒng)中。建議使用bash運行腳本 |
通過.或source | 加載/配置生效文件(環(huán)境變量,別名)可以用來實現(xiàn)include功能,八其他腳本引用到當(dāng)前腳本中 |
通過相對或絕對路徑 | 一般不推薦使用這種,系統(tǒng)腳本/服務(wù)使用腳本(加上執(zhí)行權(quán)限) |
輸入重定向符 | 不推薦使用 |
總結(jié)
相關(guān)文章
shell 腳本之用ab每隔30分鐘并發(fā)一次休息10分鐘
這篇文章給大家分享如何使用shll解決用ab每隔30分鐘并發(fā)一次休息10分鐘,需要的朋友可以參考下2019-11-11如何利用 tee 命令調(diào)試shell腳本中的管道
在編寫shell腳本時,調(diào)試是個比較麻煩的事,特別是涉及到多層管道命令的時候,會產(chǎn)生多個中間結(jié)果,tee命令的作用是從標(biāo)準(zhǔn)輸入中讀取數(shù)據(jù)寫入標(biāo)準(zhǔn)輸出或文件中,利用它可以從管道中讀取中間結(jié)果并寫入本地臨時文件中,通過中間結(jié)果可以一步一步的定位到腳本的錯誤2021-05-05shell腳本實現(xiàn)快速生成xml格式sitemap實例分享
這篇文章主要介紹了shell腳本實現(xiàn)快速生成xml格式sitemap實例分享,只是本文的腳本首先需要一個創(chuàng)建好的URL集合文件,也就是數(shù)據(jù)源才可以生成,需要的朋友可以參考下2014-12-12用shell+sendmail實現(xiàn)服務(wù)器監(jiān)控報警小腳本
用shell+sendmail寫的服務(wù)器監(jiān)控報警小腳本,有需要的朋友可以參考下2013-03-03Shell腳本之文件批量創(chuàng)建與修改的簡單方法
有時需要將文件內(nèi)容進(jìn)行修改,如果文件數(shù)量不多可以一個一個修改,那么如果文件數(shù)量很多一個一個修改很麻煩,這篇文章主要給大家介紹了關(guān)于Shell腳本之文件批量創(chuàng)建與修改的相關(guān)資料,需要的朋友可以參考下2021-06-06完美解決Linux搭建sftp出現(xiàn)Write failed:Broken pipe的問題
下面小編就為大家?guī)硪黄昝澜鉀QLinux搭建sftp出現(xiàn)Write failed:Broken pipe的問題。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-06-06