Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
601 views
in Technique[技术] by (71.8m points)

bash - 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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use

target=${1%/}

A reference.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...