11/22/2017 - 5:13 PM

Bash Snippets

Useful lines of bash code that are not full functions

#Snip will cat a file and truncate any new line character at the end
$(cat SOME_FILE | tr -d '\n')
#This is a var that will only render if another var is not null
# if REQUIRE_VAR is not null then the DEPENDENT_VAR part of the string will render
# the value you set in REQUIRED_VAR will not render

#Remove -tests from the output if it exists
if grep -q -e '-tests' <<< ${VERSION}; then
    local len1=${#VERSION}
    local len2=`expr $len1 - 6`
    VERSION=`echo $VERSION | cut -c 1-$len2`

if grep -q -e 'tests-' <<< ${VERSION}; then