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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:39:53+00:00 2026-05-24T18:39:53+00:00

I have the code in my bash scripts that works unstable: # check every

  • 0

I have the code in my bash scripts that works unstable:

# check every line of check_list file presents in my_prog output
MY_LIST=`./my_prog`
for l in $(cat check_list); do
    if ! echo -n "$MY_LIST" | grep -q -x "$l"; then
        die "Bad line: '$l'"
    fi
done

This piece of code of my huge scripting pool shows “Bad line: ‘smthng'” with probability around 1/5000. I wasn’t able to represent this event by the naked script but only in my huge scripting pool.

However this code seems to work very fine:

# check every line of check_list file presents in my_prog output
./my_prog > my_list
for l in $(cat check_list); do
    if ! grep -q -x "$l" "my_list"; then
        die "Bad line: '$l'"
    fi
done

The reason why I don’t like the second statement is that its use an intermediate file “my_list”.
What could be a problem of unstable working of the first statement?

  • 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-24T18:39:55+00:00Added an answer on May 24, 2026 at 6:39 pm

    Instead of calling grep for every line in your check_list, you can run one awk program:

    awk '
      FILENAME == ARGV[1] {check_list[$0]; next}
      $0 in check_list {
         print "bad line: " $0
         exit 1
      }
    ' check_list <(./my_prog)
    

    Or, see if there are any common lines between your program’s output and your check_list:

    common=$( comm -12 <(sort -u check_list) <(./my_prog | sort -u) )
    if [ -n "$common" ]; then
        echo "bad lines: "
        echo "$common"
        die
    fi
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have certain critical bash scripts that are invoked by code I don't control,
We have a system that has some Bash scripts running besides Java code. Since
I have an exec function in php file that execs a bash script. It
I have a share backup bash script that works as is, but it uses
He all, i have a problem with my bash script. That's my code: #!/bin/bash
I have the following code which should put programs startable in Bash. if [
I have code that references a web service, and I'd like the address of
I have some problems with a PHP script that calls a Bash script.... in
I have scripts that have one-liners or sort scripts from other languages within them.
I have a bash shell script that loops through all child directories (but not

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.