In Bash programming, I’m trying to set up a script to generate a specific link. Subsequently, i’m trying to get that script to open said link if it does not 404. curl and other programs exist on my system, but apparently i can’t get the links to autoopen, without defining a command explicitly, such as firefox [generatedLink]. What can i use to do the following:
(1) Analyze the output of curl to determine whether the generated link is valid (i.e. does not return a 404), and
(2) prompt the user whether they want to open the link in a browser, and if they say yes, open the default browser on their system to that generated link?
If you believe I should do this in some other language (C++, Python, etc.), please let me know.
NOTE i only want this to work on Linux. It does not need to be cross-platform.
Now a short explanation:
HEADis a quick script coming with libwww-perl. I used that because it’s straightforward. It just does aHEADrequest, so it’s lightweight, and it exits with error if the URL gives one;xdg-openis a nice script which detects whichever Desktop Environment you are using and opens the URL using the preferred application there. In other words, it tries hard to make sure that browser chosen by user will be used.