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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:19:50+00:00 2026-06-10T03:19:50+00:00

So, the commands: dmesg | grep ‘Attached SCSI disk’ | awk ‘{ print $5}’

  • 0

So, the commands:

dmesg | grep 'Attached SCSI disk' | awk '{ print $5}'

when executed directly from shell, works like it should, outputting:

[sdb]
[sdc]
[sda]

But, when I’m launching it with:

sh -c "dmesg | grep 'Attached SCSI disk' | awk '{ print $5}'"
# or
bash -c "dmesg | grep 'Attached SCSI disk' | awk '{ print $5}'"

I get:

[ 2.460353] sd 1:0:0:0: [sdb] Attached SCSI disk
[ 2.461348] sd 2:0:0:0: [sdc] Attached SCSI disk
[ 2.464181] sd 0:0:0:0: [sda] Attached SCSI disk

That clearly shows that the last pipe has not executed.

What am I doing wrong?

  • 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-10T03:19:51+00:00Added an answer on June 10, 2026 at 3:19 am

    Your $5 is getting evaluated too early. Change it to \$5.

    If you were to replace bash with echo, you would see that $5 is being replace by the empty string:

     % echo "dmesg | grep 'Attached SCSI disk' | awk '{ print $5}'"
     dmesg | grep 'Attached SCSI disk' | awk '{ print }'
    

    So, when bash evaluates the command, awk is going to print the entire line, not the fifth field.

    When you escape the dollar sign (by pre-prending with a backslash), the variable $5 is preserved:

    % echo "dmesg | grep 'Attached SCSI disk' | awk '{ print \$5}'"
    dmesg | grep 'Attached SCSI disk' | awk '{ print $5}'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does Git support any commands that would allow me to commit directly from a
Some commands like svn log, for example will only take one input from the
I have multiple piped commands, like this: find [options] | grep [options] | xargs
The following Groovy commands illustrate my problem. First of all, this works ( as
After deleting the partitions from a USB stick and then re-inserting the disk I
I have several commands printing text to a file using perl. During these print
Using batch commands how do I get the folder path/directory from a string? For
All the code/commands below are part of a PHP script that processes images from
I'm executing these commands from a Console Application DBCC SHRINKFILE (@FILE_NAME_MDF, 0) WITH NO_INFOMSGS
How can I give commands to Linux console (Ubuntu) from my c++ program, and

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.