Shell Programming
#Shell Programming
Bourne Shell
- Change to Bourne Shell (sh)
- % echo $SHELL
% sh
->$
- Change to Bourne Shell (sh)
Executable script
- Shebang
- #!/bin/sh
- #!/bin/bash
- #!/usr/local/bin/bash
- #!/usr/bin/env bash
- #!/usr/bin/env python
- Execution
$ sh test.sh
$ chmod a+x test.sh
$ ./test.sh
- Shebang
Shell variables
- Assignment
- Access
- Assignment
Quotation marks
- Single quotes(‘xxx’):
- 把裡面的東西當字串直接印
- 把裡面的東西當字串直接印
- Double quotes(“xxx”):
- 把裡面的東西當成special的 變數或其他東西印出
- 把裡面的東西當成special的 變數或其他東西印出
- Back quotes(
xxx
):- The stdout of the command
- The stdout of the command
- Single quotes(‘xxx’):
Shell variable operator
- “Bad” : var is not set or the value is null
- “Good” : var is set and is not null
Predefined shell variables
- Environment Variables
- Other useful variables:
• $* : all arguments are formed into a long string
• $@ : all arguments are formed into separated strings
awk
- 鳥哥awk教學
- awk讀file dir link
- 檔案類型有:
- d: directories 可用/^d/來讀取
- -: files 可用/^-/來讀取
- l: links 可用/^l/來讀取