如何在命令行中将文件路径转换为URI?
范例:
/home/MHC/directory with spaces and ümläuts
到
file:///home/MHC/directory%20with%20spaces%20and%20%C3%BCml%C3%A4uts
一种方法是使用urlencode
(通过安装在Ubuntu上sudo apt-get install gridsite-clients
)。
urlencode -m "$filepath"
会将路径转换为URI。URI的“ file://”部分将被省略,但是您可以通过bash单行代码轻松添加它:
uri=$(urlencode -m "$1"); echo "file://$uri"
或直接
echo "file://$(urlencode -m "$1")"
或者
echo -n file://; urlencode -m "$1"
非常感谢MichaelKjörling提供的参考!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句