第一个脚本
sh01.sh
#!/bin/bash
echo "hello"
执行bash sh01.sh
区别
source: 父进程中执行
bash:子进程中执行
实例 1:姓+名->姓名
#!/bin/bash
# program: input firstname and lastname, output fullname
# data: 2018-07-11
# author: peng shiyu
read -p "input your firstname:" firstname
read -p "input your lastname:" lastname
echo "your fullname is: $firstname $lastname"
说明:
第一行 #!
声明shell
其余 #
注释
开头应该尽量说明文件功能
实例 2:用当前日期创建文件
#!/bin/bash
# program: create file by date
# date: 2018-07-12
# author: peng shiyu
echo "create start..."
# 文件名
filename="file-"
date1=$(date +%Y%m%d)
file1="${filename}${date1}.txt"
# 创建文件
touch $file1
echo "create end!"