Shell命令解释器分类示例详解

Shell是负责User与Linux OS之间沟通的桥梁,Shell为用户提供了一个操作界面,User在这个界面输入指令,其实就是通过Shell向Linux Kernel传递过去,这也就是为什么Shell也叫解释器的原因,这篇文章主要给大家介绍了关于Shell命令解释器分类的相关资料,需要的朋友可以参考下

Shell命令解释器:介于  系统内核——>命令解释器——>外围应用程序:应用/命令/服务

Shell编程:bash编程

1、命令解释器

bash目前应用最广泛的一款命令解释器,红帽系列(默认),Debain,Unbantu,BASH全称:Bourne-Again Shell
dash一般Debain/Unbantu系统默认的,运行脚本推荐使用bash lidao.sh
csh,tcsh一些unix系统使用
zsh功能更多,支持更多的插件,可以更好看

2、编程语言分类

解析:直接解析型shell,python,书写代码后,通过对应解析器运行
编译:需要编译后运行C,C++

解释型

[root@localhost ~]# vim 1.py [root@localhost ~]# cat 1.py print("hrllo world!") [root@localhost ~]# python 1.py hrllo world!

3、Shell脚本执行方式

1通过sh或bash执行

[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或 . 执行

[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通过绝对路径或相对路径执行

[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、应用场景

应用及场景

通过sh或bash执行书写脚本后,最常用的方式,在其他非红帽系统中。建议使用bash运行脚本
通过.或source加载/配置生效文件(环境变量,别名)可以用来实现include功能,八其他脚本引用到当前脚本中
通过相对或绝对路径一般不推荐使用这种,系统脚本/服务使用脚本(加上执行权限)
输入重定向符不推荐使用

总结

以上就是Shell命令解释器分类示例详解的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » 脚本专栏