Bash correction (#922)

* fix bash path split example

* add two string equality and example
This commit is contained in:
Seth 2018-11-16 12:08:34 -08:00 committed by chad d
parent 2b8e8ce90c
commit 898c8d904b
1 changed files with 8 additions and 2 deletions

10
bash.md
View File

@ -154,8 +154,8 @@ echo ${STR:-5:5} # "world"
```bash ```bash
SRC="/path/to/foo.cpp" SRC="/path/to/foo.cpp"
BASE=${STR##*/} #=> "foo.cpp" (basepath) BASE=${SRC##*/} #=> "foo.cpp" (basepath)
DIR=${SRC%$BASE} #=> "/path/to" (dirpath) DIR=${SRC%$BASE} #=> "/path/to/" (dirpath)
``` ```
### Substitution ### Substitution
@ -333,6 +333,7 @@ Conditionals
| `[ NUM -gt NUM ]` | Greater than | | `[ NUM -gt NUM ]` | Greater than |
| `[ NUM -ge NUM ]` | Greater than or equal | | `[ NUM -ge NUM ]` | Greater than or equal |
| --- | --- | | --- | --- |
| `[[ STRING == STRING ]]` | Equal |
| `[[ STRING =~ STRING ]]` | Regexp | | `[[ STRING =~ STRING ]]` | Regexp |
| --- | --- | | --- | --- |
| `(( NUM < NUM ))` | Numeric conditions | | `(( NUM < NUM ))` | Numeric conditions |
@ -380,6 +381,11 @@ if [ X ] && [ Y ]; then
fi fi
``` ```
```bash
# Equal
if [[ "$A" == "$B" ]]
```
```bash ```bash
# Regex # Regex
if [[ "A" =~ "." ]] if [[ "A" =~ "." ]]