Last active
January 5, 2018 01:39
-
-
Save blizzrdof77/ef6eb6360a77f8e0753012d318469167 to your computer and use it in GitHub Desktop.
Trim a string or variable shell script.
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
# ----------------------------------------- | |
# 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