×

shell

shell编程

我的笔记 我的笔记 发表于2018-11-12 14:56:23 浏览3129 评论0

抢沙发发表评论

1.新建一个shell脚本

vi shell.sh

定义使用哪种shell版本

 

#!/bin/bash

2.变量的定义

=16

3.字符串的使用

name="zzz"定义一个字符串
sentence="my name is ${name}"echo $echo sentence
echo ${#sentence}

3.运算符

a=1b=2乘法符号需要转义
value=`expr $a \* $b`
echo ${value}

4.流程控制

if else 表达式

 [ $a ="a=b""a!=b"

for循环

for l in 1  2 3 4 5do
   echo $l
done

while

i=1while (( $i < 5 ))doecho $i
    let i++done

5.用shell脚本创建50个文件

for i in `seq 50`do
   touch hello-${i}
done

用shell脚本删除50个文件

for i in `seq 50`do
   rm hello-${i}
done

 

我的笔记博客版权我的笔记博客版权