Skip to content

Instantly share code, notes, and snippets.

@constrict0r
Last active October 18, 2019 18:11
Show Gist options
  • Save constrict0r/0f92fd5dfaf5e5dbeb823ac4566d3222 to your computer and use it in GitHub Desktop.
Save constrict0r/0f92fd5dfaf5e5dbeb823ac4566d3222 to your computer and use it in GitHub Desktop.
Bash conditionals, regex and substitutions.
# 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