Linux 系统命令及shell脚本2

7 篇文章 0 订阅
3 篇文章 0 订阅

shell脚本的常用用法

01.sh

!/bin/bash

echo “参数 1echo 2”
echo “参数长度#”  
for param in “
@”
do
echo “param:$param”
done

调用
./01.sh 1 2 3

02.sh

-d 检查文件是否存在,并且是一个目录
-e 检查file是否存在
-f 检查是否存在,并且是一个文件
-r 检查是否存在,可读
-w 检查文件是否可写
-x 是否可执行

Switch的使用 03.sh

!/bin/bash

testUser= 1case testUser in
tim)
echo “tim”;;
david)
echo “david”;;
*)
echo “默认”;;

esac

*好等于default
每个case结束两个分号
调用
./03.sh tim

for循环04.sh

!/bin/bash

for item in Mther Father Brother
do
echo “$item”

done

for循环05.sh

!/bin/bash

Family=”Mther Father Brother”
for item in Familydoecho item”

done

While 循环06.sh

!/bin/bash

a=10
while [ agt0]doa= [ a1]echo: a”
if [$a -eq 5 ]
then
echo “跳出循环”
break
fi
done

写入文件 07.sh

输出

追加输出
<输入

!/bin/bash

file=test6
echo “aa”> fileechobb>> file

‘>!’:如果存在则覆盖
‘>&’:执行时屏幕上所产生的任何信息写入指定的文件中
‘>>’:追加到文件中
‘>>&’:屏幕上的信息追加到文件中

01.sh

!/bin/bash

echo “参数 1echo 2”
echo “参数长度#”  
for param in “
@”
do
echo “param:$param”
done

调用
./01.sh 1 2 3

02.sh

-d 检查文件是否存在,并且是一个目录
-e 检查file是否存在
-f 检查是否存在,并且是一个文件
-r 检查是否存在,可读
-w 检查文件是否可写
-x 是否可执行

Switch的使用 03.sh

!/bin/bash

testUser= 1case testUser in
tim)
echo “tim”;;
david)
echo “david”;;
*)
echo “默认”;;

esac

*好等于default
每个case结束两个分号
调用
./03.sh tim

for循环04.sh

!/bin/bash

for item in Mther Father Brother
do
echo “$item”

done

for循环05.sh

!/bin/bash

Family=”Mther Father Brother”
for item in Familydoecho item”

done

While 循环06.sh

!/bin/bash

a=10
while [ agt0]doa= [ a1]echo: a”
if [$a -eq 5 ]
then
echo “跳出循环”
break
fi
done

写入文件 07.sh

输出

追加输出
<输入

!/bin/bash

file=test6
echo “aa”> fileechobb>> file

‘>!’:如果存在则覆盖
‘>&’:执行时屏幕上所产生的任何信息写入指定的文件中
‘>>’:追加到文件中
‘>>&’:屏幕上的信息追加到文件中

找文件内容
grep -n bin 06.sh
01.sh

!/bin/bash

echo “参数 1echo 2”
echo “参数长度#”  
for param in “
@”
do
echo “param:$param”
done

调用
./01.sh 1 2 3

02.sh

-d 检查文件是否存在,并且是一个目录
-e 检查file是否存在
-f 检查是否存在,并且是一个文件
-r 检查是否存在,可读
-w 检查文件是否可写
-x 是否可执行

Switch的使用 03.sh

!/bin/bash

testUser= 1case testUser in
tim)
echo “tim”;;
david)
echo “david”;;
*)
echo “默认”;;

esac

*好等于default
每个case结束两个分号
调用
./03.sh tim

for循环04.sh

!/bin/bash

for item in Mther Father Brother
do
echo “$item”

done

for循环05.sh

!/bin/bash

Family=”Mther Father Brother”
for item in Familydoecho item”

done

While 循环06.sh

!/bin/bash

a=10
while [ agt0]doa= [ a1]echo: a”
if [$a -eq 5 ]
then
echo “跳出循环”
break
fi
done

写入文件 07.sh

输出

追加输出
<输入

!/bin/bash

file=test6
echo “aa”> fileechobb>> file

‘>!’:如果存在则覆盖
‘>&’:执行时屏幕上所产生的任何信息写入指定的文件中
‘>>’:追加到文件中
‘>>&’:屏幕上的信息追加到文件中

找文件内容
grep -n bin 06.sh
01.sh

!/bin/bash

echo “参数 1echo 2”
echo “参数长度#”  
for param in “
@”
do
echo “param:$param”
done

调用
./01.sh 1 2 3

02.sh

-d 检查文件是否存在,并且是一个目录
-e 检查file是否存在
-f 检查是否存在,并且是一个文件
-r 检查是否存在,可读
-w 检查文件是否可写
-x 是否可执行

Switch的使用 03.sh

!/bin/bash

testUser= 1case testUser in
tim)
echo “tim”;;
david)
echo “david”;;
*)
echo “默认”;;

esac

*好等于default
每个case结束两个分号
调用
./03.sh tim

for循环04.sh

!/bin/bash

for item in Mther Father Brother
do
echo “$item”

done

for循环05.sh

!/bin/bash

Family=”Mther Father Brother”
for item in Familydoecho item”

done

While 循环06.sh

!/bin/bash

a=10
while [ agt0]doa= [ a1]echo: a”
if [$a -eq 5 ]
then
echo “跳出循环”
break
fi
done

写入文件 07.sh

输出

追加输出
<输入

!/bin/bash

file=test6
echo “aa”> fileechobb>> file

‘>!’:如果存在则覆盖
‘>&’:执行时屏幕上所产生的任何信息写入指定的文件中
‘>>’:追加到文件中
‘>>&’:屏幕上的信息追加到文件中

找文件内容
grep -n bin 06.sh
01.sh

!/bin/bash

echo “参数 1echo 2”
echo “参数长度#”  
for param in “
@”
do
echo “param:$param”
done

调用
./01.sh 1 2 3

02.sh

-d 检查文件是否存在,并且是一个目录
-e 检查file是否存在
-f 检查是否存在,并且是一个文件
-r 检查是否存在,可读
-w 检查文件是否可写
-x 是否可执行

Switch的使用 03.sh

!/bin/bash

testUser= 1case testUser in
tim)
echo “tim”;;
david)
echo “david”;;
*)
echo “默认”;;

esac

*好等于default
每个case结束两个分号
调用
./03.sh tim

for循环04.sh

!/bin/bash

for item in Mther Father Brother
do
echo “$item”

done

for循环05.sh

!/bin/bash

Family=”Mther Father Brother”
for item in Familydoecho item”

done

While 循环06.sh

!/bin/bash

a=10
while [ agt0]doa= [ a1]echo: a”
if [$a -eq 5 ]
then
echo “跳出循环”
break
fi
done

写入文件 07.sh

输出

追加输出
<输入

!/bin/bash

file=test6
echo “aa”> fileechobb>> file

‘>!’:如果存在则覆盖
‘>&’:执行时屏幕上所产生的任何信息写入指定的文件中
‘>>’:追加到文件中
‘>>&’:屏幕上的信息追加到文件中

找文件内容
grep -n bin 06.sh

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值