Skip to content

Instantly share code, notes, and snippets.

@wraithmonster
Created March 4, 2012 21:31
Show Gist options
  • Save wraithmonster/1974878 to your computer and use it in GitHub Desktop.
Save wraithmonster/1974878 to your computer and use it in GitHub Desktop.
Strip whitespace & trailing slashes in bash
# References:
# http://bit.ly/bash-exit-status
# http://bit.ly/bash-remove-slash
# http://www.delorie.com/gnu/docs/wget/wget_27.html
# Strip whitespace
WS=`expr "$1" : '[[:space:]]*\(.*\)[[:space:]]*$'`
# Strip whitespace and remove any trailing slashes
WS_AND_SLASHES=`expr "$1" : '[[:space:]]*\(.*\)[[:space:]]*$' | sed -e 's/\\/$//g'`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment