Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
655 views
in Technique[技术] by (71.8m points)

bash - Clean way to launch the web browser from shell script?

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 GNOME
  • www-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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
python -mwebbrowser http://example.com

works on many platforms


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...