Shell命令解释器分类

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

Shell编程:bash编程

命令解释器

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功能,八其他脚本引用到当前脚本中
通过相对或绝对路径一般不推荐使用这种,系统脚本/服务使用脚本(加上执行权限)
输入重定向符不推荐使用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值