编辑脚本文件
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有多种,如:
- Bourne Shell(/usr/bin/sh或/bin/sh)
- Bourne Again Shell(/bin/bash)
- C Shell(/usr/bin/csh)
- K Shell(/usr/bin/ksh)
- Shell for Root(/sbin/sh)
注释
# 是单行
下面的是多行
:<<EOF
...
EOF
网友评论