Remove a character from the end of a variable
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(){
date=`date "+%y%m%d_%H%M%S"`
PWD=`pwd`
path=$PWD/$target
tar czf /tmp/$date$target.tar.gz $path
}
backup
Solution 1:
Use
target=${1%/}
A reference.
Solution 2:
Use target=${1%/}
See this the parameter substitution of this bash scripting guide for more.