当前位置:网站首页>Shell编程概述
Shell编程概述
2022-06-30 12:12:00 【向上的狼】
一、Shell名词解释
1.1、Kernel
1.2、Shell
- 命令解释器(command interpreter)
- Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁。Shell 既是一种命令语言, 又是一种程序设计语言。
- Shell 是指一种应用程序,这个应用程序提供了一个界面,用户通过这个界面访问操作系统内 核的服务。
1.3、shell两大主流
- sh:
- Bourne shell(sh) ,Solaris,hpux默认shell
- Bourne again shell(bash) ,Linux系统默认shell
- csh:
- C shell(csh)
- tc shell(tcsh)
1.4、#! 声明

二、Shell脚本的执行
2.1、输入脚本的绝对路径或相对路径
注意看文件是否有执行权限, 如果没有的话, 可以给它赋予权限.
- /root/helloworld.sh
- ./helloworld.sh
- 执行的必须是一个可执行文件
2.2、bash或sh +脚本
- sh helloworld.sh
- 当脚本没有x权限时,root和文件所有者通过该方式可以正常执行
2.3、在脚本的路径前再加". " 或source
- source helloworld.sh
2.4、区别
- 第一种和第二种会新开一个bash,不同bash中的变量无法共享。
- 第三种 是在同一个shell里面执行的
Demo1:




执行过程分析:

Demo2:

分析原因: 当你使用sh hello.sh执行shell脚本的话, 因为它在执行这个脚本会重新创建一个子进程, 而进程之间的数据是不能共享的, 所以你之前创建的那个name=张三这个变量并不能识别.但是如果你使用source hello.sh来执行脚本的话, 因为执行脚本的过程中并没有重新创建新的进程, 所以依然可以对name变量进行打印.
那如何解决呢?
解决办法就在于后面的关键字export
2.5、export
- 可以将当前进程的变量传递给子进程去使用
- 将来配置profile的时候 所有的变量前必须加export
边栏推荐
- Today in history: Microsoft acquires PowerPoint developers; SGI and MIPS merge
- FlinkSQL自定义UDTF使用的四种方式
- Sword finger offer 05 Replace spaces: replace each space in the string s with "%20"“
- Iserver publishing es service query setting maximum return quantity
- Redis的基本操作的命令
- QT implementation dynamic navigation bar
- Browser plays RTSP video based on nodejs
- 品达通用权限系统(Day 7~Day 8)
- [bug solution] fiftyone reports attributeerror: module 'CV2' has no attribute 'GAPI_ wip_ gst_ Gstreamerpipeline 'error resolution
- SuperMap iClient3D 11i for Cesium三维场景中图例使用说明
猜你喜欢

Redis的基本操作的命令

Map集合

MySQL built-in functions

Hisilicon 3559 developing common sense reserves: a complete explanation of related terms

Joplin实现样式更改

Inner join and outer join of MySQL tables

Understanding and learning of MySQL indexing and optimization

【一天学awk】数组的使用

SuperMap iServer11i新功能----图例的发布和使用

SuperMap 3D SDKs_Unity插件开发——连接数据服务进行SQL查询
随机推荐
Dqn notes
海思3559 sample解析:venc
Commands for redis basic operations
Basic interview questions for Software Test Engineers (required for fresh students and test dishes) the most basic interview questions
“\“id\“ contains an invalid value“
两批次纯牛奶不合格?麦趣尔回应:正对产品大批量排查抽检
90. (cesium chapter) cesium high level listening events
7 lightweight and easy-to-use tools to relieve pressure and improve efficiency for developers, and help enterprises' agile cloud launch | wonderful review of techo day
如何利用AI技术优化独立站客服系统?听听专家怎么说!
ECDSA signature verification in crypt
90. (cesium chapter) cesium high level listening events
SuperMap iclient3d for webgl loading TMS tiles
Redis - problèmes de cache
Substrate 源码追新导读: 波卡系波卡权重计算全面更新, Governance 2.0 版本的优化和调整
Redis的基本操作的命令
Introduction to the pursuit of new subtrate source code - early May: xcm officially launched
How difficult is data governance and data innovation?
Linux系统Redis的安装
RDS MySQL数据迁移PolarDB MySQL费用可以转过去吗?
Building of Hisilicon 3559 universal platform: obtaining the modified code of data frame