在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
                  您的解决方案对我来说似乎很好
                
                
                  
                    —
                    Jamie Wong 
                    
                  
                
              
                  是的,尽管我会交换xdg-open和gnome-open
                
                
                  
                    —
                    ninjalj 2010年
                    
                  
                
              
                  请注意您的网址。很容易得到需要引用的字符,
                
                  
                    —
                    加布
                    
                  
                
              ?或者&在其中。
                
                  您应该可以删除
                
                  
                    —
                    已暂停,直到另行通知。
                    
                  
                
              eval(存在安全风险):$BROWSER http://wwww.google.com
                
                  也有
                
                  
                    —
                    机械蜗牛
                    
                  
                
              sensible-browser。