【发布时间】:2011-03-08 15:54:03
【问题描述】:
在 bash 脚本中,我需要启动用户 Web 浏览器。似乎有很多方法可以做到这一点:
$BROWSERxdg-open-
gnome-open在 GNOME 上 www-browserx-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
【问题讨论】:
-
您的解决方案对我来说似乎很好
-
是的,虽然我会交换 xdg-open 和 gnome-open
-
请注意您的网址。很容易在其中找到需要引用的
?或&之类的字符。 -
你应该可以删除
eval(这是一个安全风险):$BROWSER http://wwww.google.com -
还有
sensible-browser。
标签: bash shell command-line standards standards-compliance