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
You don't need to write a script for that. There're some tools that you can use depending on your OS:
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
open
opens files and URLs in the default or specified application.
open https://stackoverflow.com
open -a Firefox https://stackoverflow.com
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
The builtin webbrowser
Python module works on many platforms.
python -m webbrowser https://stackoverflow.com