在 bash 脚本中,我需要启动用户 Web 浏览器。似乎有很多方法可以做到这一点:
$BROWSER
xdg-open
gnome-open
在 GNOME 上www-browser
x-www-browser
- ...
是否有一种比其他方法更标准的方法可以在大多数平台上使用,或者我应该使用这样的方法:
#/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