Skip to content

Instantly share code, notes, and snippets.

@SergeyAxenov
Created December 14, 2017 03:52
Show Gist options
  • Save SergeyAxenov/807a5dc9b367c4084fc74d60157e2a52 to your computer and use it in GitHub Desktop.
Save SergeyAxenov/807a5dc9b367c4084fc74d60157e2a52 to your computer and use it in GitHub Desktop.
Trims leading and trailing slash
#!/usr/bin/env bash
string='/this is my string'
[[ $string =~ ^/(.*) ]] && string=${BASH_REMATCH[1]}
[[ $string =~ (.*)/$ ]] && string=${BASH_REMATCH[1]}
echo $string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment