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 7586807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:31:03+00:00 2026-05-30T19:31:03+00:00

Running the code below gives me the error -bash: [: -ne: unary operator expected

  • 0

Running the code below gives me the error

-bash: [: -ne: unary operator expected

res is ==””. But i thought -ne will compare a string to int. When i do get errors its the above instead of what i want which is the domain name and curls output (its silenced in the first call because it will put junk on stdout). How do i execute the if body?

#!/bin/sh
function test {
    res=`curl -I $1 | grep HTTP/1.1 | awk {'print $2'}`
    if [ $res -ne 200 ]
    then
        echo "Error on $1"
        curl -I $1
    fi
}

test invalidsite.hsdgsdhfgsgdfysgdfgsdfygsyd.com
  • 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-05-30T19:31:04+00:00Added an answer on May 30, 2026 at 7:31 pm

    If res is an empty string, your condition evaluates to [ -ne 200] which is what the error message is complaining about. Trying to fix this via ["$res" -ne 200] won’t work here either, as the empty string is not a number. Do this instead: [ -z "$res" -o "$res" -ne 200 ]. This will first check whether the string is empty (if it is, fail). If it’s not empty, check whether the value is not 200. But this still make bash panic if res is some non-integer string, so I’d really do a string comparison here: [ -z "$res" -o "$res" != "200" ]

    Edit: It just occurred to me that you can eliminate the -z if we’re already doing a string comparison and just go with [ "$res" != "200" ].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello friends i am running code given below which contains the setLogTimeEntery function and
When running the below code a type is never returned, despite there being a
When I am running below code in Code::Blocks in Windows OS. I used to
I have the below code in a bash file called 'findError.sh': #!/bin/bash filename=$1 formatindicator=\|\
I'm running code that sometimes yields this: UInt32 current; int left, right; ... //sometimes
We get an abort when a C++ exception is thrown when running code compiled
I have a thread in my application that is running code that can potentially
I have code running in an iPhone application I am developing. Basically, the code
I'm running some code through FxCop and am currently looking at clearing all of
I am running simulation code that is largely bound by CPU speed. I am

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.