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

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

    In zsh you can use the :a modifier.

    export DIRECTORY='/some//path/name//'
    
    echo "${DIRECTORY:a}"
    
    => /some/path/name
    

    This acts like realpath but doesn't fail with missing files/directories as argument.

提交回复
热议问题