views:

29

answers:

2

I want to open html files from a shell script. I know that Ubuntu has a command x-www-browser that will open the default browser on the system. I also found via some Googling that the command is part of the debian system. I was wondering if the command is available on non debian based distros. If it isn't is there a standard way of opening an html file in the default browser on a linux OS via command line? Note that I'm using Bash.

+2  A: 

You could use xdg-open.

Leiaz
+2  A: 

If you are wanting to open an HTML file that is local (and maybe even remote, I'd have to check), you can use xdg-open. This is the rough equivalent to "double-clicking" on a file to open it, so it's not limited to html files. Since you want to always open in the user's default browser, this would be the same as if they just opened it themselves.

Of course, if they have their system set up to have HTML files open in a text editor (like I did for awhile), this would backfire. But that's pretty rare.

Quick update

I just checked and xdg-open http://google.com brought up Google in Firefox (my default browser). So it does work for non-local files.

Anthony
I see that xdg-open is part of Freedesktop. This is will be available on most Linux distros, correct?
rohit.arondekar
any distro that supports freedesktop. I can't imagine there are any, but if there are, it's probably more rare than someone having gedit as their default html viewer.
Anthony