Skip to content

Instantly share code, notes, and snippets.

@blizzrdof77
Last active January 5, 2018 01:39
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 blizzrdof77/ef6eb6360a77f8e0753012d318469167 to your computer and use it in GitHub Desktop.
Save blizzrdof77/ef6eb6360a77f8e0753012d318469167 to your computer and use it in GitHub Desktop.
Trim a string or variable shell script.
# -----------------------------------------
# Trim string
#
# @1 = string
# -----------------------------------------
function trim () {
local s2 s="$*"
# note the tab character in the expressions of the following two lines when copying
until s2="${s#[ ]}"; [ "$s2" = "$s" ]; do s="$s2"; done
until s2="${s%[ ]}"; [ "$s2" = "$s" ]; do s="$s2"; done
echo "$s"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment