Last active
October 18, 2019 18:11
-
-
Save constrict0r/0f92fd5dfaf5e5dbeb823ac4566d3222 to your computer and use it in GitHub Desktop.
Bash conditionals, regex and substitutions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Verify if variable contains text. | |
if [[ "$my_var" =~ 'my-word' ]]; then | |
echo 'Contains it.' | |
fi | |
# Replace text inside variable. | |
my_var="${my_var//search/replacement}" | |
# Trim string. | |
my_var="${my_var## }" | |
my_var="${my_var%% }" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment