User Tools

Site Tools


bash_functions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
bash_functions [2014/09/29 02:13] – [show array] k2patelbash_functions [2020/08/10 02:35] (current) – external edit 127.0.0.1
Line 357: Line 357:
  
 [[ https://www.linkedin.com/groups/Fridays-function-revword-Reverse-order-3716796.S.5916260779903975428?view=&item=5916260779903975428&type=member&gid=3716796&trk=eml-b2_anet_digest-hero-1-hero-disc-disc-0&midToken=AQG8JYIVdmXjvA&fromEmail=fromEmail&ut=13sqjyjg1356s1 | From Article ]] [[ https://www.linkedin.com/groups/Fridays-function-revword-Reverse-order-3716796.S.5916260779903975428?view=&item=5916260779903975428&type=member&gid=3716796&trk=eml-b2_anet_digest-hero-1-hero-disc-disc-0&midToken=AQG8JYIVdmXjvA&fromEmail=fromEmail&ut=13sqjyjg1356s1 | From Article ]]
 +
 +==== 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##*[!$_char]}
 +_trim=${_trim%"$_trim_string"}
 +_trim_string=${_trim%%[!$_char]*}
 +_trim=${_trim#"$_trim_string"}
 +is_var "$_var" &&
 +printf -v "$_var" %s "$_trim" ||
 +printf '%s\n' "$_trim"
 +}
 +</code>
 +
 +[[ https://www.linkedin.com/groups/Fridays-function-trim-Trim-spaces-3716796.S.5908643378429460481?view=&item=5908643378429460481&type=member&gid=3716796&trk=eml-b2_anet_digest-hero-1-hero-disc-disc-0&midToken=AQG8JYIVdmXjvA&fromEmail=fromEmail&ut=2lgJiLIHdb56s1 | From Article ]]
bash_functions.1411956790.txt.gz · Last modified: 2020/08/10 02:28 (external edit)