Score:0

bash script: why does test check more than exact matches?

au flag
j0h

I'm trying to make HAL 9000. I have a file that contains "dialog" from the movie, and a wordlist that has words in EEPROM, at their respective memory locations, and chips where the words reside in memory. I wrote a bash script that reads the movie dialog, and should output the memory addresses, and chips. It seems to work when the words are longer than one letter. When the words are 1 letter (ie: i, a), it seems to output every instance where the letter is found in a word. The bash script:

#!/bin/bash
#Read dialog get the word on a line, then find the memory location and chip it is on
#rec_column2 is the address in the chip for the word 
#cs=Chip Select, the value of rec_column3
#wordlist is the library xlsx converted via: for i  in *.xlsx; do  libreoffice --headless --convert-to csv "$i" ; done
#then put in all lower case because I don't know how to compare values that only differ by case
#command used: tr '[:upper:]' '[:lower:]' < input.csv > wordlist.csv
input="dialog"
while IFS= read -r line
do

while IFS="," read -r rec_column1 rec_column2 rec_column3 
do
if test "$line" = "$rec_column1"
    then
           echo "// " $line " , " $rec_column1 " :: " $rec_column2 ", " $rec_column3
           
           #echo "digitalWrite($rec_column3,LOW);"
           #echo "SPI.transfer($rec_column2);"
           #echo "digitalWrite($rec_column3,HIGH);"
           #echo "delay(850);"     
fi

done < wordlist.csv

done < $input

[words not in the library have no output1

The wordlist, with memory locations is here. The dialog for HAL 9000 is here. so again, in the event the word is more than one letter, the script seems to work. why does it check single letters against every word containing that letter? how do I not do that? output

j0h avatar
au flag
j0h
so weird, this posted on my computer an I saw it post legit. now I've come up with a solution, and the post is borked.
muru avatar
us flag
Please don't post screenshots of text. Copy the text here and use code formatting.
j0h avatar
au flag
j0h
@muru, is there a text compare mode for the coding? Im trying to show the comparison of input to output. I thought separating them would be more confusing.
muru avatar
us flag
The normal code block is fine, just keep them in two separate code blocks.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.