bash_functions
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| bash_functions [2014/09/29 01:53] – [floating point multiplication] k2patel | bash_functions [2020/08/10 02:35] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 340: | Line 340: | ||
| [[https:// | [[https:// | ||
| + | |||
| + | ==== Reverse Word ==== | ||
| + | <code bash> | ||
| + | revword() #@ Reverse the order of characters in STRING | ||
| + | { #@ USAGE: revword STRING [VAR] | ||
| + | local _n _word=$1 _var=$2 _len _r _rw= _l | ||
| + | while read -n1 _l | ||
| + | do | ||
| + | _rw=$_l$_rw | ||
| + | done <<< | ||
| + | [[ ${_var^^} =~ ^[A-Z_][A-Z0-9_]*$ ]] && | ||
| + | printf -v " | ||
| + | printf ' | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | [[ https:// | ||
| + | |||
| + | ==== Trim Spaces ==== | ||
| + | <code bash> | ||
| + | trim() #@ Trim spaces (or char in $2) from both ends of $1 | ||
| + | { #@ USAGE: trim STRING [CHAR [VAR]] | ||
| + | local _trim_string _trim=$1 _char=${2:- } _var=$3 | ||
| + | _trim_string=${_trim## | ||
| + | _trim=${_trim%" | ||
| + | _trim_string=${_trim%%[!$_char]*} | ||
| + | _trim=${_trim#" | ||
| + | is_var " | ||
| + | printf -v " | ||
| + | printf ' | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | [[ https:// | ||
bash_functions.1411955604.txt.gz · Last modified: 2020/08/10 02:28 (external edit)
