第一个linux shell脚本

编辑脚本文件

vim test.sh
#!/bin/bash
#  single comment
:<<EOF
comment 1
comment 2
comment 3
EOF

echo "Hello World !"

赋予执行脚本

chmod +x ./test.sh
-rwxr-xr-x. 1 root root 34 1月  13 22:25 test.sh

运行结果

[root@localhost shell]# ./test.sh 
Hello World !

代码解释

第一行中的#!/bin/bash 告诉操作系统使用什么解释器来执行。linux提供的shell有多种,如:

  1. Bourne Shell(/usr/bin/sh或/bin/sh)
  2. Bourne Again Shell(/bin/bash)
  3. C Shell(/usr/bin/csh)
  4. K Shell(/usr/bin/ksh)
  5. Shell for Root(/sbin/sh)

注释
# 是单行
下面的是多行
:<<EOF
...
EOF

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容