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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:40:38+00:00 2026-06-13T02:40:38+00:00

Can someone please explain this? I ran the commands as shown below $ cat

  • 0

Can someone please explain this? I ran the commands as shown below

$ cat `bash`

$ ls

$ ctrl+D

and it’s giving me some unexpected output on terminal.

NOTE: bash is in backquotes.

  • 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-13T02:40:39+00:00Added an answer on June 13, 2026 at 2:40 am

    Good question! The “unexpected output” is cat printing all of the files found by ls in the cwd. Detailed explanation follow:

    On your first line:

    $ cat `bash`
    

    The bash part actually spawns a new shell from your original shell because bash is enclosed by backquotes (backquotes means to run the enclosed program in this context)

    Then when you do:

    $ ls
    

    This is actually done in the newly spawned bash shell. It lists the directory of wherever the newly spawned bash shell is (should be the same as the original). This, in turn, in essence changes the cat command in the first step to

    $ cat file_1 file_2 ... file_x
    

    (basically all of the files in that directory returned by ls. However, you won’t see these results yet because the output is waiting to be printed to the stdout of your original shell : cat is waiting to evaluate the stdout of your new bash shell.)

    Lastly, when you do:

    $ ctrl+D
    

    It exits the new bash shell that you spawned from your original shell, and then cat outputs everything that got printed to stdout in the new shell (the search results from ls) into your old shell.

    You can verify what I just said by:

    $ cd ~/
    $ mkdir temp_test_dir
    $ cd temp_test_dir
    $ echo "some text for file1" > file1
    $ echo "other text for file2" > file2
    

    Now run what you had in your question:

    $ cat `bash`
    $ ls
    $ ctrl+D
    

    And this is what you should see:

    some text for file1
    other text for file2
    

    in some order, which is just cat outputting all of the files that were found by ls.

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

Sidebar

Related Questions

Can someone please explain this phenomenon? I am using Mojarra 2.1.6 - Glassfish 3.1.2.
Can someone please explain to me how this responsive approach works? This was done
Can someone please explain why I'm getting this error Type mismatch: cannot convert from
I have a feeling this XML is not valid, can someone please explain why?
Could someone please help explain why I can't get this to work? I properly
Can some one please explain why this loop never 'breaks' and goes on forever
Can someone please explain why ?___SID=U is appearing in some Magento URLs on my
I have regex which reads: @<img\s*[^>]*>(?:\s*?</img>)? Can someone please explain this part: (?:\s*?)? What
Can someone please explain this to me? I have the following code: <form action=<?php
Can someone please explain this? As I understand it provides less precision..Is it a

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.