shell 基础(4)- 创建和使用Shell脚本的格式
2019-11-27 本文已影响0人
足__迹
原因: 节省时间,提交效率减少重复工作
创建格式
touch create_file.sh
第一行需要写明分类
# !/usr/bin/bash
# Author : starry sky
# date : 19,11
# Info : This is a script that validates the creation of a shell file
执行程序
echo "执行"[root@iz2ze8p943jz0rcey20ijlz test]# cat create_file.sh
# !/usr/bin/bash
# Author : starry sky
# date : 19,11
# Info : This is a script that validates the creation of a shell file
echo "执行"[root@iz2ze8p943jz0rcey20ijlz test]# bash create_file.sh
执行
[root@iz2ze8p943jz0rcey20ijlz test]# ./create_file.sh
bash: ./create_file.sh: 权限不够
[root@iz2ze8p943jz0rcey20ijlz test]# chmod +x create_file.sh
[root@iz2ze8p943jz0rcey20ijlz test]# ./create_file.sh
执行
[root@iz2ze8p943jz0rcey20ijlz test]# source create_file.sh
执行
注释:

# !/usr/bin/bash
# Author : starry sky
# date : 19,11
# Info : This is a script that validates the creation of a shell file
echo "执行"
:<<!
中间是注释信息
!
函数

function hello2 {
echo "方式二"
echo "$1"
echo "$2"
echo "$3"
}
hello2 $3 $2 $1

参数
-
函数体调用参数
image.png
- 调用函数给函数传参
