How to make script support file:/// notation?
When I copy any file and paste it in console or text editos it is passed as
file:///home/user/path/file
when I pass it to script it is not found
What is the easiest way to convert that to normal linux path or somehow make script support it?
for example
cat file:///home/user/path/file
says
No such file or directory
I don't know of any commands that convert between file urls and file paths, but you can convert with python, or any other language with bindings to gio. E.g.:
$ python -c 'import gio,sys; print(gio.File(sys.argv[1]).get_path())' file:///home/user/path/file%20with%20spaces
/home/user/path/file with spaces
You can also use urlencode
(sudo apt-get gridsite-clients
):
$ echo "$(urlencode -d "file:///folder/with%20spaces")"
file:///folder/with spaces
$ echo "$(urlencode -d "file:///folder/with%20spaces"|cut -c 8-)"
/folder/with spaces
If you don't need hexadecimal support, you can just use cut -c 8-
. Alternatively, you could use urlencode with any other method of removing the file://
(sed, brace expansion, etc.)