Added another entry

This commit is contained in:
Dylan Araps 2018-06-15 15:57:17 +10:00
parent 3a74faa8bd
commit 1aea36ac90
1 changed files with 20 additions and 0 deletions

View File

@ -52,6 +52,7 @@ scripts and not full blown utilities.
* [Strip first occurrence of pattern from string.](#strip-first-occurrence-of-pattern-from-string)
* [Strip pattern from start of string.](#strip-pattern-from-start-of-string)
* [Strip pattern from end of string.](#strip-pattern-from-end-of-string)
* [Check if string contains a substring.](#check-if-string-contains-a-substring)
* [Variables](#variables)
* [Assign and access a variable using a variable.](#assign-and-access-a-variable-using-a-variable)
* [Arrays](#arrays)
@ -390,6 +391,25 @@ $ rstrip "The Quick Brown Fox" " Fox"
The Quick Brown
```
## Check if string contains a substring.
```shell
# Normal
if [[ "$var" == *sub_string* ]]; then
printf '%s\n' "sub_string is in var"
fi
# Inverse (substring not in string).
if [[ "$var" != *sub_string* ]]; then
printf '%s\n' "sub_string is not in var"
fi
# This works for arrays too!
if [[ "${arr[*]}" == *sub_string* ]]; then
printf '%s\n' "sub_string is in array."
fi
```
# Variables
## Assign and access a variable using a variable.