Last active
January 2, 2016 17:39
-
-
Save coderofsalvation/8338454 to your computer and use it in GitHub Desktop.
returns part of string
This file contains hidden or 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
| # returns part of string | |
| # @param string input | |
| # @param string startoffset | |
| # @param string number of characters | |
| # | |
| # usage: substr foobar 0 3 (outputs 'foo') | |
| # echo "foobar" | substr 0 3 (outputs 'foo') | |
| # short="$( substr "foobar" 0 3 )"; echo "$short" (outputs 'foo') | |
| function substr(){ | |
| if [[ -n "$3" ]]; then echo "${1:$2:$3}"; | |
| else cat - | while read line; do a="$line"; b="$1"; c="$2"; echo "${a:b:c}"; done; fi; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment