Skip to main content

Bash functions to remove leading and trailing forward slashes in Bash.

#!/usr/bin/env bash

# args:
# 	input - $1
remove_trailing_slash() {
    local input="${1:-}"
    echo "${input%/}"
}

# args:
# 	input - $1
remove_leading_slash() {
    local input="${1:-}"
    echo "${input#/}"
}