从每个参数中删除尾部斜杠的最简单方法是什么? [英] What is the simplest way to remove a trailing slash from each parameter?

查看:19
本文介绍了从每个参数中删除尾部斜杠的最简单方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 '$@' 数组中的每个参数中删除尾部斜杠,以便 rsync 按名称复制目录的最简单方法是什么?

What is the simplest way to remove a trailing slash from each parameter in the '$@' array, so that rsync copies the directories by name?

rsync -a --exclude='*~' "$@" "$dir"

<小时>

标题已更改以进行澄清.要了解有关多个尾部斜杠的评论和答案,请参阅编辑历史记录.

推荐答案

你可以使用${parameter%word} 详细的扩展此处.这是一个演示行为的简单测试脚本:

You can use the ${parameter%word} expansion that is detailed here. Here is a simple test script that demonstrates the behavior:

#!/bin/bash

# Call this as:
#   ./test.sh one/ two/ three/ 
#
# Output:
#  one two three

echo ${@%/}

这篇关于从每个参数中删除尾部斜杠的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆