1.输出hello world
helloWorld.sh的内容
#!/bin/bash
#输出hello world
#xie
#2018年5月16日21:39:06
echo -e "hello world \n"
2.用户分别输入姓和名,系统显示全名
fullName.sh
#!/bin/bash
#输入姓和名,系统显示全名
#xie
#2018年5月16日21:46:02
read -p "please input your firstName:" firstName
read -p "please input your lastName:" lastName
echo -e "your full name is: $firstName $lastName \n"
注意:”please input your firstName:”和 firstName这两个中间要有空格,否则会报变量无效
3.利用 date 进行档案的建立
![这里写图片描述](https://img-blog.csdn.net/20180516222203856?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3d1XzA5MTY=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70) touchFileByDate.sh
#!/bin/bash
#创建文件,文件名为:自定义前缀+日期
#xie
#2018年5月16日22:07:44
read -p "please input file frirst name:" firstName
#为了避免用户随意按enter,而没有前缀
fileName=${firstName:-"fileName"}
#利用date获取后缀
date1=`date --date='2 days ago' +%Y%m%d`
date2=`date --date='-1 days ago' +%Y%m%d`
date3=`date +%Y%m%d`
#date3为当天
#date2为1天后
#date1为2天前
file1="$fileName""-""$date1"
file2="$fileName""-""$date2"
file3="$fileName""-""$date3"
#建立文件
touch $file1
touch $file2
touch $file3
4.两个变量相乘
crossTwoNumber.sh
#/bin/bash
#两个变量相乘
#xie
#2018年5月16日23:00:40
echo -e "please input two number \n"
read -p "please input first number:" firstNumber
read -p "please input second number:" secondNumber
total=$(($firstNumber*$secondNumber))
echo -e "$firstNumber x $secondNumber = $total"
参考文献:鸟哥的linux私房菜