Xdg-open does not work when it receives other output from the command

Say I have a unique file called file.ext . It is indexed by my Ubuntu field, so the locate file.ext correctly gives me a (single) location, for example /usr/local/some/place/file.ext .

So, I thought this:

 locate file.ext | xdg-open 

will open the file with the default application associated with the file type (there is one, this is not a problem), as if I entered xdg-open /usr/local/some/place/file.ext

Instead, I get a "usage" message from xdg-open , as if it were being called with no arguments.

So the question is, did I get something wrong with the pipes? Or is this a problem with this particular team?

+4
source share
1 answer

Because you need to pass the file name as an option, not the data on stdin. To do this, use xargs:

 locate file.ext | xargs xdg-open 

or just a subshell:

 xdg-open "$( locate file.ext )" 
+11
source

Source: https://habr.com/ru/post/1486387/


All Articles