Skip to content

Instantly share code, notes, and snippets.

@jemyzhang
Created November 2, 2017 08:51
Show Gist options
  • Save jemyzhang/d4612d97909e0de5140ca092540c840e to your computer and use it in GitHub Desktop.
Save jemyzhang/d4612d97909e0de5140ca092540c840e to your computer and use it in GitHub Desktop.
common functional scripts
# 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