Linux鸟哥视频学习笔记29

学习shell scripts


实操
which sh 查看sh位置
ll /bin/sh

shell格式


第1个scripts:输出hello world

实操
vi sh01.sh
#!/bin/bash
#Program:
#    this scripts is used to print hello world
#History:2020-03-31  Jack  1.0.0
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export  PATH

echo "hello world"
exit 0

sh sh01.sh
或 ./sh01.sh
echo $? 
注:若sh脚本没有可执行权限,执行chmod u+x sh01.sh 给脚本文件赋权

第2个scripts:使用read,输出所输入数据


实操
vi sh02.sh
#!/bin/bash
#Program: this program is used to print your input
#History:22020-03-31  linc 1.0.0
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

read -p "请输入你的姓:" xing
read -p "请输入你的辈分:" bei
read -p "请输入你的名:" ming
echo "your name is : $xing $bei $ming"

sh sh02.sh


第3个scripts:使用所输入文件名建立文件


实操
vi sh03.sh
#!/bin/bash
#Program: this scripts is used to input name to cread file or dir
#History:2020-03-31 jack 1.0.0
PATH=/bin:/sbin:/usr/bin:usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

read -p "please input a file name:" filename
file1="$filename""one"
file2="$filename""two"

dir="$filename""three"

touch $file1
touch $file2
mkdir $dir

sh sh03.sh


第4个scripts:计算数值


实操
vi sh04.sh
#!/bin/bash
#program:this scripts is used to add * - two number
#History:2020-03-31 1.0.0
PATH=/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

read -p "please input your first number:" firnu
read -p "please input your second number:" secnu

total=$(($firnu*secnu))
echo "$firnu * $secnu= $total"

sh sh04.sh
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值