linux:bash
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
linux:bash [11/04/2025 15:50] – andrew | linux:bash [10/09/2025 12:56] (current) – [for loop] andrew | ||
---|---|---|---|
Line 30: | Line 30: | ||
[[linux: | [[linux: | ||
+ | |||
===== Generic script frameworks ===== | ===== Generic script frameworks ===== | ||
Line 43: | Line 44: | ||
[[linux: | [[linux: | ||
+ | |||
==== Print tab character. ==== | ==== Print tab character. ==== | ||
Line 67: | Line 69: | ||
==== Running multiple commands ==== | ==== Running multiple commands ==== | ||
- | Join two or more commands together, just rune them in turn and don't care if they succeed or fail:- | + | Join two or more commands together, just run them in turn and don't care if they succeed or fail:- |
$ command1 ; command2 | $ command1 ; command2 | ||
Line 107: | Line 109: | ||
Unlike setting variables where a space round the '' | Unlike setting variables where a space round the '' | ||
+ | |||
===== if elif else ===== | ===== if elif else ===== | ||
Line 166: | Line 169: | ||
do | do | ||
echo " | echo " | ||
+ | done | ||
+ | |||
+ | |||
+ | subnets= | ||
+ | subnet-02dc9fac8fd877129 | ||
+ | subnet-0f8b1423c13b2cd79 | ||
+ | subnet-049f0d086b3590d8b | ||
+ | |||
+ | |||
+ | for subnet in ${subnets[@]} | ||
+ | do | ||
+ | echo " | ||
done | done | ||
Line 192: | Line 207: | ||
===== while loop ===== | ===== while loop ===== | ||
- | | + | Multiline: |
- | { | + | |
- | print "$line\n"; | + | |
- | } | + | |
- | | + | |
+ | print "$SOMETHING\n"; | ||
+ | } | ||
+ | | ||
+ | |||
+ | |||
+ | On one line:- | ||
+ | while [ condition ]; do print " | ||
+ | |||
===== Time duration of operation and record exit status ===== | ===== Time duration of operation and record exit status ===== | ||
Line 319: | Line 343: | ||
- | ===== Arrays ===== | + | ===== Arrays |
Bash array example, indices start at zero, so below [1] returns the second element (' | Bash array example, indices start at zero, so below [1] returns the second element (' |
linux/bash.1744386655.txt.gz · Last modified: by andrew