开发者

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

开发者 https://www.devze.com 2023-05-11 09:57 出处:网络 作者: 情哥是小白
目录1、命令解释器2、编程语言分类3、Shell脚本执行方式4、应用场景总结Shell命令解释器:介于  系统内核——>命令解释器——>外围应用程序:应用/命令/服务
目录
  • 1、命令解释器
  • 2、编程语言分类
  • 3、Shell脚本执行方式
  • 4、应用场景
  • 总结

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

Shell编程:bash编程

1、命令解释器

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

2、编程语言分类

解析:直接解析型shell,python,书写代码后,通过对应解析器运行
编译:需要编android译后运行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/shhttp://www.devze.comell
root
[root@localhost shell]# bash 01.exec.way.sh 
localhost.localdomain
/root/s编程hell
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 开发者_devopsshell]# ./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.exjsec.way.sh 
localhost.localdomain
/root/shell
root

4、应用场景

应用及场景

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

总结

0

精彩评论

暂无评论...
验证码 换一张
取 消