Update 'bash_programming.md'

This commit is contained in:
wp 2022-09-07 17:51:39 -05:00
parent fcdb4f385e
commit 6f7836735a
1 changed files with 44 additions and 3 deletions

View File

@ -108,13 +108,28 @@ EOT
}
```
Bash test. Returns True if test expression passes
```
if [ -z "${MAKE_TARGETS}" ]; then
# do stuff
fi
```
Bash negative test. Returns True if test expression does not passes
```
if [ ! -z "${MAKE_TARGETS}" ]; then
# do stuff
fi
```
Common bash test expressions
https://www.gnu.org/software/bash/manual/html_node/Bash-Conditional-Expressions.html and https://stackoverflow.com/a/21164441
```
The following test operators return "True" if the file exists
-a file :: Any file type
-e file :: Any file type
-f file :: Any regular file (ie not a block, socket, pipe, symlink, etc.)
-e file :: Check for file existence, regardless of type (node, directory, socket, etc.)
-f file :: Any regular file that is not a directory
-b file :: Block special file
-c file :: Character file
-d file :: Directory type
@ -135,6 +150,7 @@ Other common test operators
-v varname :: True if 'varname' is set and has been assigned a value
-R varname :: True if varname is set and is a name reference
-n string :: True if length of string is not zero
-z string :: True if length of string is zero
string1 == string2 :: True if the strings are equal
string1 = string2 :: True if the strings are equal. POSIX conformant
string1 != string2 :: True if the strings are not equal
@ -148,4 +164,29 @@ arg1 -lt arg2 :: True if arg1 is less than arg2
arg1 -le arg2 :: True if arg1 is less than or equal to arg2
arg1 -gt arg2 :: True if arg1 is greater than arg2
arg1 -ge arg2 :: True if arg1 is greater than or equal to arg2
```
```
Command substitution
https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html
```
$(command)
`command`
```
Shell Arthimetic - https://www.gnu.org/software/bash/manual/html_node/Shell-Arithmetic.html
Brace expansions
https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html
```
mkdir /usr/local/src/bash/{old,new,dist,bugs}
```
or
```
chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
```
Parameter (variable) expansion - https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html and https://wiki.bash-hackers.org/syntax/pe
GNU BASH reference - https://www.gnu.org/software/bash/manual/html_node/index.html
BASH Hackers Wiki - https://wiki.bash-hackers.org/