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

前端 未结 6 851
清酒与你
清酒与你 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:46

    The accepted answer will trim ONE trailing slash.

    One way to trim multiple trailing slashes is like this:

    VALUE=/looks/like/a/path///
    
    TRIMMED=$(echo $VALUE | sed 's:/*$::')
    
    echo $VALUE $TRIMMED
    

    Which outputs:

    /looks/like/a/path/// /looks/like/a/path
    

提交回复
热议问题