Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8323355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:42:09+00:00 2026-06-08T23:42:09+00:00

In Bash programming, I’m trying to set up a script to generate a specific

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:42:10+00:00Added an answer on June 8, 2026 at 11:42 pm
    if HEAD "${URL}" >/dev/null; then
        printf '%s' 'URL ok, open browser? [y/n] '
        read -n 1
        echo
    
        if [ "${REPLY}" = y ]; then
            xdg-open "${URL}"
        fi
    else
        echo 'URL not ok.'
    fi
    

    Now a short explanation:

    1. HEAD is a quick script coming with libwww-perl. I used that because it’s straightforward. It just does a HEAD request, so it’s lightweight, and it exits with error if the URL gives one;
    2. The asking part is not really important here. It’s just one of many solutions;
    3. xdg-open is 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.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam new to bash script programming. I want to implement a bash script deploymLog
From a programming standpoint, when you set the bash shell to use vi or
I'm writing a bash script that spawns a number of background processes. I'd like
I am currently learning bash programming and dont really understand why the passing argument
Let me start by saying I'm new at programming, mac osx, and bash. I'm
#!/bin/bash echo SCRIPT: $0 echo Enter Customer Order Ref (e.g. 100018) read P_CUST_ORDER_REF echo
Using bash, how can one get the number of files in a folder, excluding
Hi I am a newbe to bash programming and need some help. I am
we are programming a bash like shell in C but we have problems with
I am writing a bash script to search for a pattern in a file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.