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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:15:41+00:00 2026-06-17T20:15:41+00:00

[ -f /tmp/myfile.txt ] && echo File exists || echo No such file How

  • 0
[ -f /tmp/myfile.txt ] && echo "File exists" || echo "No such file"

How does this work? Specifically the the evaluation of && and ||.

  • 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-17T20:15:42+00:00Added an answer on June 17, 2026 at 8:15 pm

    && and || are control operators that determine whether the following command should be executed based on the exit status of the prior command. From man (1) bash:

    The control operators && and || denote AND lists and OR lists, respectively. An AND list has the form

      command1 && command2
    

    command2 is executed if, and only if, command1 returns an exit status of zero.

    An OR list has the form

      command1 || command2
    

    command2 is executed if and only if command1 returns a non-zero exit status.
    The return status of AND and OR lists is the exit status of the last
    command executed in the list.

    [, or test, returns a zero exit status if the command passes the test. From help test:

    test: test [expr]
    Exits with a status of 0 (true) or 1 (false) depending on
    the evaluation of EXPR.

    So when you do

    [ -f /tmp/myfile.txt ] && echo foo || echo bar
    

    what you’re really saying is (read this carefully, please) If the file exists, echo foo. If the file does not exist or the echo foo command fails, echo bar.

    This is the subtle, but critical difference between these control operators and an if…then command.

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

Sidebar

Related Questions

Well you know I can use this: <?php $myfile = 'myfile.txt'; $command = tac
tmp-file contains: database_1 database_2 database_3 I want to run a command like mysqldump DATABASE
rm -r /cbbconfg/BRCH/tmp rm: cannot determine if this is an ancestor of the current
I have a directory /tmp/dir with two types of file names /tmp/dir/abc-something-server.log /tmp/dir/xyz-something-server.log ..
Using Struts 2: when will the .tmp file - that gets created after uploading
I want to save a .txt file in my iPhone app, but I want
given the > 4gb file myfile.gz, I need to zcat it into a pipe
this is how my file structure is. [..] are folders [public] [libs] [crontab] [logs]
I want to do the same thing as open MYFILE, >, data.txt; print MYFILE
I've got a lot of secrets stored in myfile.txt , which I have to

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.