In a bash script, I need to launch the user web browser. There seems to be many ways of doing this:
$BROWSER
xdg-open
gnome-open
on GNOMEwww-browser
x-www-browser
- ...
Is there a more-standard-than-the-others way to do this that would work on most platforms, or should I just go with something like this:
#/usr/bin/env bash
if [ -n $BROWSER ]; then
$BROWSER 'http://wwww.google.com'
elif which xdg-open > /dev/null; then
xdg-open 'http://wwww.google.com'
elif which gnome-open > /dev/null; then
gnome-open 'http://wwww.google.com'
# elif bla bla bla...
else
echo "Could not detect the web browser to use."
fi
xdg-open
is standardized and should be available in most distributions.Otherwise:
eval
is evil, don't use it.Here is an example:
Maybe this version is slightly better (still untested):
works on many platforms
OSX:
or
or simply...
You could use the following:
It won't run the user's but rather the system's default X browser.
See: this thread.
This may not apply exactly to what you want to do, but there is a really easy way to create and launch a server using the
http-server
npm package.Once installed (just
npm install http-server -g
) you can puthttp-server -o
in your bash script and it will launch a server from the current directory and open a browser to that page.