Shell学习笔记
一笑释青春
学无止境,怎能止步
展开
-
Shell--对字符串的操作
1.其主要是利用了Shell内置的一系列字符串操作符号.具体的相关操作符号介绍如下:${#string} $string的长度${string:position} 在$string中,从位置$position开始提取子串${string:position:length}原创 2016-12-03 09:33:41 · 592 阅读 · 0 评论 -
Shell--变量
1、 定义变量:yourName="jfxu" #"="两边不能有空格 2、只读变量/删除变量yourName="jfxu" readonly yourName #变量只读unset yourName #删除变量3、使用变量echo $yourName echo ${yourName} #原创 2016-12-03 09:44:04 · 232 阅读 · 0 评论 -
Shell--数组
1、定义数组myArray=(a b c d "e")或 myArray=(abcd“e”)或myArray[0]=amyArray[1]=bmyArray[2]=cmyArray[3]=dmyArray[4]= "e" 2、读取数组echo ${myArray[0]} #输出aecho ${原创 2016-12-03 09:47:17 · 186 阅读 · 0 评论 -
shell--echo/printf
1、 echo是Shell的一个内部指令,用于在屏幕上打印出指定的字符串。str="fish"eg:echo "I an a ${str}" #I an a fisheg:echo "\"I an a ${str}\"" #"I an a fish"注:echo自动换行2、printf命令用于格式化输出, 是echo命令的增强版语法格式:原创 2016-12-03 09:50:02 · 251 阅读 · 0 评论 -
Shell--流程控制
1、if else (条件判断)eg:a=10b=20if [ ${a} == ${b} ]then echo "a=b"elif [ ${a} -gt ${b} ]then echo "a>b"else echo "afi注:若没有else,就不要写else2、case 语句eg: a=10原创 2016-12-03 09:52:45 · 230 阅读 · 0 评论 -
Shell--函数
1、定义格式:function functionName() #关键字function可以省略{ list of commands [return value]} 函数返回值: #函数的返回值只能是整数可以显式增加return语句;如果不加,会将最后一条命令运行结果作为返回值。eg:原创 2016-12-03 09:55:08 · 212 阅读 · 0 评论 -
shift
Linux shell脚本中shift的用法说明shift命令用于对参数的移动(左移),通常用于在不知道传入参数个数的情况下依次遍历每个参数然后进行相应处理(常见于Linux中各种程序的启动脚本)。示例1:依次读取输入的参数并打印参数个数:run.sh:[java] view plain copy#!/转载 2017-05-24 11:09:31 · 225 阅读 · 0 评论 -
Shell--基本运算符
1.常用的算术运算符`expr $a + $b` a+b`expr $a - $b` a-b`expr $a \* $b` a*b`expr $a / $b` a/b`expr $a % $b` a%ba = $b 赋值[ $a == $b ] 判断是否相等原创 2016-12-03 09:29:03 · 339 阅读 · 0 评论