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

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

问题描述

从'$ @'数组中的每个参数中删除斜杠的最简单方法是什么,以便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}扩展.html#Shell-Parameter-Expansion"rel =" noreferrer>此处.这是一个演示行为的简单测试脚本:

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天全站免登陆