Linux shell Script初识
shell secript:
执行方式的差异:
./ sh执行都是在创建一个子程序来执行,只会继承环境变量,
其中的变量如果export声明,子程序的子程序会继承,不会升级为环境变量
source 的执行方式是把脚本放到父程序的环境执行,
其中的变量如果export声明,会升级成环境变量
test判断,[]判断是一样的,建议使用[]的判断方式




默认变量($0, $1......)
$,$....位置变量,代表参数
$#:代表参数的个数
$@:代表参数"$1""$2""$3""$4"
$*:代表"$1c$2c$3c$4",其中c为分隔符,默认是空白
shift:变量偏移
每执行一次,判断的位置向右移动一个
条件判断:
if [ 条件判断式 ];then
内容
fi
&&代表AND; ||代表or
-a:代表and; -o代表or
if [ 条件判断式 ];then
内容
elif [ 条件判断式 ];then
内容
fi
利用case .... esac判断
case $变量 in
"第一个变量内容")
程序段
;;
"第二个变量内容")
程序段
;;
"*")
exit 1
;;
esac
循环:
while do done
while [ condition ]
do
程序段
done
当condition成立时,就执行循环,不成立则停止
until [ condition ]
do
程序段
done
当condition成立时,就立则停止,不成立,则循环
for ... do ...done
for var in con1 con2 con3
do
程序段
done
数值处理
for((初始值; 限制值; 执行步骤))
do
程序段
done
乱数与阵列array
${RANDOM} 的取值范围[0,32767]
#!/bin/bash
#
e[1]="aaa"
e[2]="bbb"
e[3]="ccc"
en=3
check=$(( ${RANDOM} * ${en} / 32767 + 1))
echo ${e[${check}]}
function函数:
function fname(){
程序段
}
函数也具有位置变量,$0,$1,$2
shell script的debug
sh:
-n:不要执行script,仅查询语法问题
-v:在执行前,把script内容输出到屏幕上
-x:将使用到的script内容显示在屏幕上
Linux shell Script初识的更多相关文章
- 一个改动配置文件的linux shell script
不久以前,以前搜到一篇博客是读取配置文件的,http://www.cnblogs.com/bo083/archive/2012/11/19/2777076.html,用到如今,感觉十分方便.感谢作者. ...
- Linux shell script All In One
Linux shell script All In One refs xgqfrms 2012-2020 www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
- Linux Shell Script目录
目录 Linux Shell基础 开始Shell编程 代码 示例代码查看:https://github.com/Furzoom/demo-C/tree/master/src/shell
- Linux Shell(初识)
什么是Shell:Shell是一个命令解释器. Linux下支持shell的种类: 1. Bourne Shell(简称sh) 2.C Shell(简称csh) 3.Korn Shell(简称ksh ...
- fastq to tasta using linux shell script
#!/bin/bash usage() { echo " "; echo "############################################### ...
- (copy) Shell Script to Check Linux System Health
source: http://linoxide.com/linux-shell-script/shell-script-check-linux-system-health/ This article ...
- Shell script for logging cpu and memory usage of a Linux process
Shell script for logging cpu and memory usage of a Linux process http://www.unix.com/shell-programmi ...
- (原创)鸟哥linux学习script shell相关笔记
在使用鸟哥linux进行script shell学习的过程中碰到一些不太明白的知识点,在这里进行一些记录 1. [root@www scripts]# vi sh03.sh #!/bin/bash # ...
- linux基础之Shell Script入门介绍
本文介绍下,学习shell script编程的入门知识,通过几个入门实例,带领大家走进shell script的神圣殿堂,呵呵,有需要的朋友参考下. 本文转自:http://www.jbxue.com ...
随机推荐
- LCIS HDU - 3308 (线段树区间合并)
LCIS HDU - 3308 Given n integers. You have two operations: U A B: replace the Ath number by B. (inde ...
- docker 批量命令
docker中 启动所有的容器命令: docker start $(docker ps -a | awk '{ print $1}' | tail -n +2) docker中 关闭所有的容器命 ...
- 解决ubuntu16.04 ‘E: 无法获得锁 /var/lib/dpkg/lock-frontend - open (11: 资源暂时不可用) ’ 问题
问题: 当运行sudo apt-get install/update/其他命令时,会出现如下提示: E: 无法获得锁 /var/lib/dpkg/lock-frontend - open (11: 资 ...
- 注意力机制和Seq2seq模型
注意力机制 在"编码器-解码器(seq2seq)"⼀节⾥,解码器在各个时间步依赖相同的背景变量(context vector)来获取输⼊序列信息.当编码器为循环神经⽹络时,背景变量 ...
- CMS-熊海网站内容管理系统漏洞测试
开门见山 在虚拟机中搭建网站,本机访问http://192.168.31.68/ 一.SQL注入获取管理员账号密码 1. 点开一篇文章,存在get请求参数 2. 手工注入无果,使用sqlmap,后跟- ...
- Python—使用列表构造栈数据结构
class Stack(object): """ 使用列表实现栈 """ def __init__(self): self.stack = ...
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)报错
0 环境 系统环境:win10 1 正文 先检查Mapper接口与相关联xml文件是否对应,需要检查包名,namespace位置是否写对,curd时id名称等能否对应上 常规步骤: :检查mapper ...
- linuxmint截图
利用import命令截图,并设置快捷键 shift + PrtScrSysRq: 选中区域截图. 设置快捷键的时候,提示: Ctrl + PrtScrSysRq: 复制截图到剪切板 PrtScrSys ...
- ruoyi IpUtils
package com.ruoyi.common.utils; import java.net.InetAddress; import java.net.UnknownHostException; i ...
- Educational Codeforces Round 80 (Rated for Div. 2)D E
D枚举子集 题:https://codeforces.com/contest/1288/problem/D题意:给定n个序列,每个序列m个数,求第i个和第j个序列组成b序列,b序列=max(a[i][ ...