bash
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
bash [2020/08/12 17:14] – created shawn | bash [2020/08/12 19:07] (current) – [Functions] Adds tips shawn | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | |||
+ | ''# | ||
====== set options ====== | ====== set options ====== | ||
+ | |||
+ | '' | ||
Commonly used options: | Commonly used options: | ||
- | * -x: turns on debug output, logging each command as it is executed | + | * '' |
- | * -e: causes the script to exit on most command failures (non-zero exit codes) | + | * '' |
- | * -u: treats unset variables and parameters other than the special parameters @ or * as an error when performing parameter expansion | + | * '' |
- | * -o pipefail: causes the script to exit if a command in a pipeline fails | + | * '' |
- | * use a+ to unset them if necessary | + | * use a + to unset them if necessary |
Many more options available: | Many more options available: | ||
Line 14: | Line 18: | ||
====== Variables ====== | ====== Variables ====== | ||
- | * $@ - All of the arguments as individual strings | + | * '' |
- | * " | + | * '' |
- | * $# - The number of arguments | + | * '' |
- | * $1..n - Where n is an integer, the nth argument in the list | + | * '' |
- | * $0 - The command name | + | * '' |
- | * $? - The last exit code | + | * '' |
- | * $IFS - Internal/ | + | * '' |
+ | |||
+ | ====== Functions ====== | ||
+ | |||
+ | Declaring a function (needs to happen before use): | ||
+ | |||
+ | '' | ||
+ | |||
+ | - or - | ||
+ | |||
+ | ''< | ||
+ | |||
+ | * Nothing ever goes inside parentheses. | ||
+ | * Passed parameters can be accessed with '' | ||
+ | ====== Tips ====== | ||
+ | * [[https:// |
bash.1597252487.txt.gz · Last modified: 2020/08/12 17:14 by shawn