編輯腳本文件
vim test.sh
#!/bin/bash
# single comment
:<<EOF
comment 1
comment 2
comment 3
EOF
echo "Hello World !"
賦予執(zhí)行腳本
chmod +x ./test.sh
-rwxr-xr-x. 1 root root 34 1月 13 22:25 test.sh
運(yùn)行結(jié)果
[root@localhost shell]# ./test.sh
Hello World !
代碼解釋
第一行中的#!/bin/bash 告訴操作系統(tǒng)使用什么解釋器來(lái)執(zhí)行压恒。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