Created
November 2, 2017 08:51
-
-
Save jemyzhang/d4612d97909e0de5140ca092540c840e to your computer and use it in GitHub Desktop.
common functional scripts
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
# strip white spaces and tabs from string | |
string_trim() { | |
local str=$1 | |
echo "$str" | sed -E 's/^[ \t]*//' | sed -E 's/[ \t]*$//' | |
} | |
# convert string to lower case | |
string_lower() { | |
local str=$1 | |
echo "$str" | tr "[:upper:]" "[:lower:]" | |
} | |
math_calc() { | |
local format="$1" | |
local equation="$2" | |
echo | awk "{printf \"$format\", $equation}" | |
} | |
math_compare() { | |
local comparison=$1 | |
if [ $(echo "$comparison" | bc -l) -eq 1 ]; then | |
return 0 | |
else | |
return 1 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment