Answers for "shell trim"

1

shell trim

STR="${STR//(^[ ]+|[ ]+$)/}"

# ${STR//--regex--/--replacement--} = replace all
# ${STR/--regex--/--replacement--} = replace one
# ^[ ]+ = empty character([ ])s(+) at the start(^) of the string
# [ ]+$ = empty character([ ])s(+) at the end($) of the string
# (A|B) = A or B
Posted by: Guest on April-15-2021

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language