Remove a character from the end of a variable

Viewed 70678

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
4 Answers

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.

What did I do?

Substitute 2.19/* to be 2.19.

Solution

VER="2.19/foo-bar"
NEWVER=${VER%/*}
Related