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

  • Home
  • SEARCH
  • 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 7739799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:36:44+00:00 2026-06-01T08:36:44+00:00

I have a script in which I have a line which does put the

  • 0

I have a script in which I have a line which does put the third line fetched in my variable like this:

variable=`sed -n '3 p' /home/nmsadm/abc.txt`

So variable holds this value Which is in third line of abc.txt. In my case it
will be a one word line or an empty/blank line.

How can I compare the variable in a shell script to know if it’s an empty/blank line?
echo $variable fetched me an empty line.

What is the comparison i need to here so that
I am assured it’s an empty line? Something like this:

if [ "$variable" = "comparison" ]; then
  • 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-01T08:36:45+00:00Added an answer on June 1, 2026 at 8:36 am

    Empty or undefined:

    if [ -z "${variable-}" ]
    

    Single newline:

    if [ "${variable-}" = $'\n' ]
    

    Undefined:

    if [ "${variable+defined}" != defined ]
    

    Note, the last command is not the opposite of

    if [ "${variable-undefined}" = undefined ]
    

    To see why, try running variable=undefined first. "${variable+defined}" has only two possible values: The empty string or defined.

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

Sidebar

Related Questions

I have a script which creates a user-defined object like this: obj = new
I have a script which contains the following line: propFile=${0%/*}/anteater.properties What does ${0%/*} mean?
I have a script which, each time is called, gets the first line of
I have this script which basically toggles a bgColor class on and off so
I have a python script which does a partial checkout. At some point I
Currently, I have a script which does the following. If I have text file
I have a bash shell script which has the line: g=$(/bin/printf ${i}) when ${i}
I have an aprox 1000 line-script which loops through all servers in AD. The
I have the following script which does not work 100%, it returns about 20
I have a script which generates like 16000 html pages and saves it in

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.