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 revision Previous revision
Last revision Both sides next revision
bash_functions [2014/09/28 22:13]
k2patel [show array]
bash_functions [2014/09/28 22:22]
k2patel [Reverse Word]
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.txt ยท Last modified: 2017/07/01 22:12 by k2patel