学习shell scripts

Linux鸟哥视频学习笔记29

Linux鸟哥视频学习笔记29

Linux鸟哥视频学习笔记29
实操
which sh 查看sh位置
ll /bin/sh

shell格式

Linux鸟哥视频学习笔记29

Linux鸟哥视频学习笔记29


第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
 

相关文章:

  • 2021-07-19
  • 2021-04-09
  • 2021-06-12
  • 2021-12-07
  • 2021-04-24
  • 2021-08-31
  • 2021-08-15
  • 2022-01-11
猜你喜欢
  • 2021-06-19
  • 2021-10-04
  • 2021-10-01
  • 2021-07-27
  • 2021-08-30
  • 2021-08-25
  • 2021-05-08
相关资源
相似解决方案