Advertisement
justin_hanekom

Bash trim string function

Mar 16th, 2019
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.45 KB | None | 0 0
  1. ################################################################################
  2. # Function:     trim
  3. # Description:  Trims any/all whitespace from the beginning and end of a string
  4. # Arguments:    $1 :- The string from which to trim whitespace
  5. # Outputs:      Prints string with any leading/trailing whitespace removed
  6. function trim {
  7.     local str="$1"
  8.     str="${str#"${str%%[![:space:]]*}"}"
  9.    str="${str%"${str##*[![:space:]]}"}"
  10.     echo "$1"
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement