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

原因: 节省时间,提交效率减少重复工作

创建格式

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
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容