AJ Bohara
AJ Bohara

Reputation: 11

Bash Echo Not Printing

#!/bin/bash

declare -A keyPair

while IFS=, read key value; do
    keyPair[$key]=$value
done <$2

while read line; do
    for char in $line; do
        decoded=${keyPair[$char]}
        echo -n "$decoded"
    done
done <$1

this is my code above. I am trying to output text which reads from a file and replaces words in the file corresponding to those in an associative array.(e.g. AA: {waste: run}, the program will replace all instances of 'waste' with 'run'). I am tying to echo the output without a new line. I assume this works with the echo -n, however my console does not output anything. However if i run the same script with just an echo without -n, my program outputs the following:

zoo
garage
water
mountain

run
father
zoo
underwater
fast

run
walk

foo
fast
father

I would like to make it so that it looks like this

zoo garage water mountain

run father zoo underwater fast

run walk

foo fast father

Any help would be appreciated. Thank you very much.

Upvotes: 0

Views: 1726

Answers (1)

AJ Bohara
AJ Bohara

Reputation: 11

The issue stemmed from having DOS line endings in my input txt files. Fixing the DOS line endings seemed to have fixed all my issues.

Read more: stackoverflow.com/tags/bash/info

Upvotes: 1

Related Questions