当前位置:网站首页>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
边栏推荐
- 江西财经大学智慧江财登录分析
- Sword finger offer 05 Replace spaces: replace each space in the string s with "%20"“
- 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
- Substrate 源码追新导读: 5月中旬: Uniques NFT模块和Nomination Pool
- Joplin implements style changes
- Swagger2 automatically generates API documents
- 品达通用权限系统(Day 7~Day 8)
- Set集合
- Basic interview questions for Software Test Engineers (required for fresh students and test dishes) the most basic interview questions
- qt msvc 安装及调试
猜你喜欢

MySQL built-in functions

Basic interview questions for Software Test Engineers (required for fresh students and test dishes) the most basic interview questions

Google refutes rumors and gives up tensorflow. It's still alive!

QT implementation dynamic navigation bar

Ensemble de cartes

【一天学awk】正则匹配

【MySQL】MySQL的安装与配置

品达通用权限系统(Day 7~Day 8)

Hisilicon 3559 universal platform construction: introduction to YUV format

SuperMap iServer11i新功能----图例的发布和使用
随机推荐
MySQL判断执行条件为NULL时,返回0,出错问题解决 Incorrect parameter count in the call to native function ‘ISNULL‘,
Some commonly used hardware information of the server (constantly updated)
Tencent cloud Database Engineer competency certification was launched, and people from all walks of life talked about talent training problems
Basic interview questions for Software Test Engineers (required for fresh students and test dishes) the most basic interview questions
SQLSERVER 查询编码是 936 简体中文GBK,那我是写936 还是写GBK?
Sword finger offer 05 Replace spaces: replace each space in the string s with "%20"“
Commands for redis basic operations
视频按每100帧存一个文件夹,处理完再图片转视频
RDS MySQL数据迁移PolarDB MySQL费用可以转过去吗?
60 divine vs Code plug-ins!!
FlinkSQL自定义UDAF使用的三种方式
Charles打断点修改请求数据&响应数据
FlinkSQL自定义UDTF使用的四种方式
Understanding and learning of MySQL indexing and optimization
FlinkSQL自定义UDATF实现TopN
A review of quantum neural networks 2022 for generating learning tasks
腾讯二面:@Bean 与 @Component 用在同一个类上,会怎么样?
海思3559万能平台搭建:获取数据帧修改后编码
Global capital market 101: Breit, one of the best investment targets for domestic high net worth people
Lvgl widget styles