Advertisement
justin_hanekom

Bash function to remove slash from end of string

Mar 16th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.43 KB | None | 0 0
  1. ################################################################################
  2. # Function:     chomp_slash
  3. # Description:  Removes any trailing slash ("/") from a string
  4. # Arguments:    $1 :- String from which to remove any trailing slashes
  5. # Ouputs:       Prints string with trailing slashes removed
  6. function chomp_slash {
  7.     local dir="$1"
  8.     while [ "${dir:(-1)}" = '/' ]; do
  9.         dir=${dir::-1}
  10.     done
  11.     echo "${dir}"
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement