Created
November 25, 2014 15:47
-
-
Save maxwelleite/24cfacea249ba77f6df1 to your computer and use it in GitHub Desktop.
Collection of useful string functions for BASH programming
This file contains 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
#!/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