Skip to content

Instantly share code, notes, and snippets.

@maxwelleite
Created November 25, 2014 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxwelleite/24cfacea249ba77f6df1 to your computer and use it in GitHub Desktop.
Save maxwelleite/24cfacea249ba77f6df1 to your computer and use it in GitHub Desktop.
Collection of useful string functions for BASH programming
#!/bin/bash
# Author: Maxwel Leite
# file-name: functions-str.sh
# Website: http://needforbits.tumblr.com/
# Description: Collection of useful string functions for BASH programming
# License: GPLv3
# Description: Remove leading and trailing whitespace characters
# @param string source string
# usage: result="$(trim " a b c d ")"
trim(){
[ -z "$1" ] && return
printf "$(echo "$1" | sed -e 's/^[[:space:]]*//g;s/[[:space:]]*$//g')"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment