Shell script to open a URL

后端 未结 6 1062
既然无缘
既然无缘 2021-02-01 13:51

How do I write a simple shell script (say script.sh), so that I can pass a URL as an argument while executing?

I want a browser to start with the page opened on that URL

6条回答
  •  遥遥无期
    2021-02-01 14:53

    You don't need to write a script for that. There're some tools that you can use depending on your OS:

    Linux

    xdg-open is available in most Linux distributions. It opens a file or URL in the user's preferred browser (configurable with xdg-settings).

    xdg-open https://stackoverflow.com
    

    macOS

    open opens files and URLs in the default or specified application.

    open https://stackoverflow.com
    open -a Firefox https://stackoverflow.com
    

    Windows

    You can use the start command at the command prompt to open an URL in the default (or specified) browser:

    start https://stackoverflow.com
    start firefox https://stackoverflow.com
    

    Cross-platform

    The builtin webbrowser Python module works on many platforms.

    python -m webbrowser https://stackoverflow.com

提交回复
热议问题