diff options
author | William Carroll <wpcarro@gmail.com> | 2016-05-04T18·12-0700 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2016-05-04T18·12-0700 |
commit | 530ce588967387eee0563ca4906d2dcced405195 (patch) | |
tree | b3de8d260808b375306e6c11150c95bd4cc36f58 /.js_to_bash.sh | |
parent | 4a0783fc87d80e5ffc58b7d1a7212a4a41d6cb6b (diff) |
Adds javascript functions for bash
Diffstat (limited to '.js_to_bash.sh')
-rw-r--r-- | .js_to_bash.sh | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/.js_to_bash.sh b/.js_to_bash.sh new file mode 100644 index 000000000000..734aa498dc70 --- /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 +} |