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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:52:47+00:00 2026-06-17T07:52:47+00:00

I know this has to be something simple, but I’m just not seeing it.

  • 0

I know this has to be something simple, but I’m just not seeing it. We have a file, SpeakerList.txt, which contains a series of single lines of a speaker in our database. new.trs holds a space-delimited version of the database. I need to verify that we find the speaker in the database, so I’m running a grep for lines that start with the speaker name. The following code always results in the if statement at the end triggering for every speaker. I’ve got a similar bit of code that checks for file existence and it works just fine. What am I missing? I know that my grep loop is running — I’ve tried it with debug echo lines. I’ve also tried printing out the $speakerFound field and verified that it is indeed blank at the end, even when I have a statement showing that it was marked “found” earlier.

for i in `cat SpeakerList.txt`
do 
  speakerFound="" 
  echo "Speaker: $i"
  grep "^$i" ~/work/new.trs | while read line
  do 
    fileName=`echo $line | cut -d' ' -f 2`
    speakerFound="found"
    break
  done

  if [ "$speakerFound" == "" ]; then
    echo "$i not found in database."
  fi
done
  • 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-17T07:52:48+00:00Added an answer on June 17, 2026 at 7:52 am

    You are setting your speakerFound variable in a subshell. Read this link for more details, but in general:

    • When you redirect the stdin of a loop in bash, the loop will execute in a subshell.
    • Because the loop is a subshell, variable assignments inside the loop will not be visible outside of the loop.

    One solution is to use a file on disk to contain the result (write it in the inner loop, and read it back in when you need the result).

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

Sidebar

Related Questions

I'm sure this is something simple but I am just not seeing it. My
I know this has been asked different ways several times, but I'm just not
I know this has a really simple explanation, but I've been spoiled by not
I know this is probably something so simple that I am just not able
i know this has already been asked here in stackoverflow, but i could not
I know this has been asked thousands of times but I just can't find
I know this is something simple but I can't figure it out :( I'm
Maybe I'm just missing something simple, but it doesn't seem like anyone else has
I know this type of question has been asked before, but I could not
I know this has probably been asked before but for my problem I cannot

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.