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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:51:18+00:00 2026-05-23T06:51:18+00:00

I read that in shell, true command returns 0 => logical true. false command

  • 0

I read that in shell,
true command returns 0 => logical true.
false command return 1 => logical false.
But I get surprising results when i run.

if [ 0 ]
then
echo "0 is true."
else
echo "0 is false."
fi

if [ 1 ]
then
echo "1 is true."
else
echo "1 is false."
fi

if [ false ]
then
echo "false is true."
else
echo "false is false."
fi

if [ true ]
then
echo "true is true."
else
echo "true is false."
fi

I get these results.

0 is true.
1 is true.
false is true.
true is true.

  • 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-23T06:51:19+00:00Added an answer on May 23, 2026 at 6:51 am

    The test if [ 0 ] tests whether 0 is the empty string (it isn’t) and returns true if it is not empty. The test if [ 1 ] similarly tests whether 1 is the empty string and returns true if it is not empty. Likewise, the other two tests check whether the strings true and false are empty…

    If you want to test the commands, execute the commands:

    if false; then echo False is true; else echo False is false; fi
    if true ; then echo True  is true; else echo True  is false; fi
    

    Most machines don’t have commands called 0 or 1, so you can’t readily invoke them as commands.

    You could also experiment with:

    if sh -c "exit 1"; then echo Shell exited as true; else echo Shell exited as false; fi
    if sh -c "exit 0"; then echo Shell exited as true; else echo Shell exited as false; fi
    

    In 7th Edition Unix, /bin/test (or possibly /usr/bin/test) was the test program, but you would normally find a link /bin/[. When it was invoked by the name [, it demanded that its last argument was ], so you could write a square bracketed condition. (Macs with macOS 10.14.6 Mojave still have /bin/[ — it still works. Linux systems usually have /usr/bin/[, and it still works too.)

    Shortly after that, the test operation was built into the shell, instead of being a separate executable, but the semantics remained largely unchanged. Because they are now different (built-in vs the executable), sometimes the test operations have different functionality. POSIX defines a baseline; various shells and systems provide various extensions.

    To this day, the autoconf suite recommends the use of test over [, though that is primarily because it uses square brackets for another purpose.

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

Sidebar

Related Questions

i have the following code: def cmds(cmd): cmd= Popen(cmd, shell=True, stdout=PIPE) lines = command.stdout.read().splitlines()
I read that some webmail services prefetch url links in emails. The GET request
I read that early builds of Chrome supported ActiveX, but was later restricted to
I read that Python does not actually support 2D arrays but rather an array
I read that great post on Visual Studio 2008 annoyances, but didn't see this
I have the following python function that allows me to run shell commands from
In Ruby, I want to be able to: run a command line (via shell)
I need help return everything after I can read. I understand that this will
I have requirement that: When i execute shell script , it should read all
I read that .NET uses connection pooling. For example, if I instantiate a bunch

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.