Shell--快速入門
阿新 • • 發佈:2020-12-08
1 編寫指令碼
- 新建 /export/01.sh 檔案
#!/bin/bash
echo 'hello world'
#!
是一個約定的標記,它告訴系統這個指令碼需要什麼直譯器來執行
,即 使用哪一種 Shell。- echo 命令用於向視窗輸出文字。
2 執行shell指令碼
執行方式一
[[email protected] shells]# /bin/sh 01.sh
hello world
[[email protected] shells]# /bin/bash 01.sh
hello world
- 問題: bash 和 sh 是什麼關係?
sh 是 bash 的 快捷方式
執行方式二sh 檔名
方式一的簡化方式
[[email protected] shells]# bash hello.sh
hello world
[[email protected] shells]# sh hello.sh
hello world
- 問題: 請思考 為什麼可以省略 /bin/
- 因為
PATH環境變數
中增加了 /bin/目錄, 所以 使用/bin/sh等類似指令時, 可以省略 /bin
- 因為
執行方式三./檔名
[[email protected] shells]# ll
總用量 4
-rw-r--r--. 1 root root 32 3月 14 00:20 01.sh
[ [email protected] shells]# ./01.sh
-bash: ./01.sh: 許可權不夠
- 許可權不夠怎麼辦?
chmod 755 檔名
[[email protected] shells]# chmod 755 01.sh
[[email protected] shells]# ll
總用量 4
-rwxr-xr-x. 1 root root 32 3月 14 00:20 01.sh
- 再次執行:
[[email protected] shells]# ./01.sh
hello world!