美文网首页
shell 基础(4)- 创建和使用Shell脚本的格式

shell 基础(4)- 创建和使用Shell脚本的格式

作者: 足__迹 | 来源:发表于2019-11-27 18:49 被阅读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 
执行

注释:

image.png
# !/usr/bin/bash
# Author : starry sky
# date : 19,11
# Info : This is a script that validates the creation of a shell file

echo "执行"

:<<!
中间是注释信息
!

函数

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

参数

  • 函数体调用参数


    image.png
  • 调用函数给函数传参
image.png

相关文章

网友评论

      本文标题:shell 基础(4)- 创建和使用Shell脚本的格式

      本文链接:https://www.haomeiwen.com/subject/othmwctx.html