bash
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| bash [2011/10/18 13:11] – [Indirect Referance] k2patel | bash [2020/08/10 02:35] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Bash ====== | ====== Bash ====== | ||
| + | * [[ Floating Point Calculation ]] | ||
| + | |||
| ==== Bash Short-Cut ==== | ==== Bash Short-Cut ==== | ||
| Line 119: | Line 121: | ||
| [ FILE1 -ef FILE2 ] True if FILE1 and FILE2 refer to the same device and inode numbers. | [ FILE1 -ef FILE2 ] True if FILE1 and FILE2 refer to the same device and inode numbers. | ||
| [ -o OPTIONNAME ] True if shell option " | [ -o OPTIONNAME ] True if shell option " | ||
| - | [ -z STRING ] True | + | [ -z STRING ] True |
| [ -n STRING ] or [ STRING ] True if the length of " | [ -n STRING ] or [ STRING ] True if the length of " | ||
| [ STRING1 == STRING2 ] True if the strings are equal. " | [ STRING1 == STRING2 ] True if the strings are equal. " | ||
| Line 269: | Line 271: | ||
| </ | </ | ||
| + | |||
| + | ==== Bash alias and complition ==== | ||
| + | Using command completion for alias in bash. | ||
| + | <code bash ~/ | ||
| + | alias c='/ | ||
| + | export HLIST | ||
| + | HLIST=`cat ~/ | ||
| + | HLIST=" | ||
| + | HLIST=$(echo ${HLIST} | sort | uniq) | ||
| + | complete -W " | ||
| + | </ | ||
| + | |||
| + | ==== Control case ==== | ||
| + | In Bash 4: | ||
| + | |||
| + | To lowercase | ||
| + | |||
| + | <code bash> | ||
| + | $ string=" | ||
| + | $ echo ${string,} | ||
| + | a FEW WORDS | ||
| + | $ echo ${string,,} | ||
| + | a few words | ||
| + | $ echo ${string,, | ||
| + | a FeW WoRDS | ||
| + | |||
| + | $ string=" | ||
| + | $ declare -l string | ||
| + | $ string=$string; | ||
| + | a few words | ||
| + | </ | ||
| + | |||
| + | To uppercase | ||
| + | |||
| + | <code bash> | ||
| + | $ string=" | ||
| + | $ echo ${string^} | ||
| + | A few words | ||
| + | $ echo ${string^^} | ||
| + | A FEW WORDS | ||
| + | $ echo ${string^^[aeiou]} | ||
| + | A fEw wOrds | ||
| + | |||
| + | $ string=" | ||
| + | $ declare -u string | ||
| + | $ string=$string; | ||
| + | A FEW WORDS | ||
| + | </ | ||
| + | |||
| + | Toggle (undocumented) | ||
| + | |||
| + | <code bash> | ||
| + | $ string=" | ||
| + | $ echo ${string~~} | ||
| + | a fEW wORDS | ||
| + | $ string=" | ||
| + | $ echo ${string~} | ||
| + | a fEW wORDS | ||
| + | $ string=" | ||
| + | $ echo ${string~} | ||
| + | A Few Words | ||
| + | </ | ||
| + | |||
| + | Capitalize (undocumented) | ||
| + | |||
| + | <code bash> | ||
| + | $ string=" | ||
| + | $ declare -c string | ||
| + | $ string=$string | ||
| + | $ echo $string | ||
| + | A few words | ||
| + | </ | ||
| + | |||
| + | Title case: | ||
| + | |||
| + | <code bash> | ||
| + | $ string=" | ||
| + | $ string=($string) | ||
| + | $ string=${string[@]^} | ||
| + | $ echo $string | ||
| + | A Few Words | ||
| + | |||
| + | $ declare -c string | ||
| + | $ string=(a few words) | ||
| + | $ echo ${string[@]} | ||
| + | A Few Words | ||
| + | </ | ||
| + | |||
| + | To turn off a declare attribute, use " | ||
| + | |||
| + | ==== Bash Tips / Tricks ==== | ||
| + | |||
| + | === Quating === | ||
| + | Bash has a special form of quoting, $' | ||
| + | <code bash> | ||
| + | re=' | ||
| + | </ | ||
| + | |||
| + | === History Size === | ||
| + | <code bash> | ||
| + | HISTSIZE=1500000 | ||
| + | HISTFILESIZE=1500000 | ||
| + | HISTTIMEFORMAT=" | ||
| + | </ | ||
| + | |||
| + | === Truth Table === | ||
| + | <code bash> | ||
| + | These two commands not the same: | ||
| + | |||
| + | command1 && command2 || command3 | ||
| + | |||
| + | if command1 | ||
| + | then | ||
| + | command2 | ||
| + | else | ||
| + | command3 | ||
| + | fi | ||
| + | </ | ||
| + | |||
| + | In the if-then-else, | ||
| + | |||
| + | <code bash> | ||
| + | for c1 in true false; do for c2 in true false; do echo "$c1 && $c2 || c3"; (echo c1; $c1) && (echo c2; $c2) || echo c3; done; done | ||
| + | </ | ||
| + | |||
| + | And the output: | ||
| + | |||
| + | <code bash> | ||
| + | true && true || c3 | ||
| + | c1 | ||
| + | c2 | ||
| + | true && false || c3 | ||
| + | c1 | ||
| + | c2 | ||
| + | c3 | ||
| + | false && true || c3 | ||
| + | c1 | ||
| + | c3 | ||
| + | false && false || c3 | ||
| + | c1 | ||
| + | c3 | ||
| + | </ | ||
| + | [[ http:// | ||
| + | ==== Networked Info ==== | ||
| + | |||
| + | * [[ Can we Hide Code ]] | ||
| ==== Bash FAQ ==== | ==== Bash FAQ ==== | ||
bash.1318943507.txt.gz · Last modified: 2020/08/10 02:28 (external edit)
