Bash auto completion appends a / at the end of a directory name. How I can strip this off from a positional parameter?
#!/bin/sh
target=$1
function backup()
Use
target=${1%/}
A reference.
Use target=${1%/}
See this the parameter substitution of this bash scripting guide for more.
Be careful, bash3 added perl-similar regex to bash. The guide mentioned covers this as well as the official guide at GNU , but not all references do.
Substitute 2.19/*
to be 2.19
.
VER="2.19/foo-bar"
NEWVER=${VER%/*}
I think better solution to canonize paths is realpath $path
or with -m
option if it doesn't exist.
This solution automaticaly removes unnecessary slashes and adds pwd