What is the simplest way to remove a trailing slash from each parameter?

前端 未结 6 791
清酒与你
清酒与你 2021-01-30 05:55

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         


        
6条回答
  •  日久生厌
    2021-01-30 06:45

    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 ${@%/}
    

提交回复
热议问题