[root@linux-server ~]# vim helloworld.sh ---.sh代表这个文件是个shell脚本, 拓展名后缀,如果省略.sh则不易判断该文件是否为shell脚本

  1. #!/usr/bin/env bash ---shebang蛇棒, 解释器, 翻译 2. #

Author: soso666

Email: soso666@163.com ---这就是注释, 你没看错

Github: https:github.com/soso666

Date: 2019/12/24

  1. printf "hello world\n"

功能说明:打印hello world [root@linux-server ~]# sh helloworld.sh hello world [root@linux-server ~]# chmod +x helloworld.sh [root@linux-server ~]# ./helloworld.sh [root@linux-server ~]# /root/helloworld.sh hello world

第一行: “#!/usr/bin/env bash”叫做shebang, shell语法规定shell脚本文件第一行为整个文件的解释器 第二行: 为“#”开头的行为注释行默认不会被程序所读取, 用来说明文件及标定所属人员使用, 也可用来解释程序 第七行: 为格式化打印语句printf, printf可以把后面的“hello world”打印到指定的终端中, \n 为换行符

bash 脚本测试: 1.这将执行该脚本并显示所有变量的值 [root@linux-server ~]# sh -x /root/helloworld.sh

  • printf 'hello world\n' hello world 2.不执行脚本只是检查语法模式,将返回所有错误语法 [root@linux-server ~]# sh -n /root/helloworld.sh 3.执行脚本前把脚本内容显示在屏幕上 [root@linux-server ~]# sh -v /root/helloworld.sh #!/usr/bin/env bash
阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: shell