From 530ce588967387eee0563ca4906d2dcced405195 Mon Sep 17 00:00:00 2001 From: William Carroll Date: Wed, 4 May 2016 11:12:28 -0700 Subject: [PATCH] Adds javascript functions for bash --- .js_to_bash.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .js_to_bash.sh diff --git a/.js_to_bash.sh b/.js_to_bash.sh new file mode 100644 index 000000000..734aa498d --- /dev/null +++ b/.js_to_bash.sh @@ -0,0 +1,32 @@ +# js function syntax for bash + +function trimend { + LENGTH=${#1} + AMT=$2 + TAKE=$((LENGTH-AMT)) + echo $1 | cut "-c-$TAKE" +} + +function trimfront { + TMP0=$(echo $1 | rev) + TMP1=$(trimend $TMP0 $2 | rev) + echo $TMP1 +} + +function length { + echo ${#1} +} + +function slice { + STR=$3 + AMT0=$1 + AMT1=$2 + + LEN=$(length $STR) + BACK=$((LEN-AMT1)) + + RES0=$(trimfront $STR $AMT0) + RES1=$(trimend $RES0 $BACK) + + echo $RES1 +}