从变量末尾删除字符 [英] Remove a character from the end of a variable
本文介绍了从变量末尾删除字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Bash自动完成功能会在目录名称的末尾附加一个/.如何从位置参数中删除呢?
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
推荐答案
使用
target=${1%/}
A 查看全文