1

I have 2 text files "${LinkP}" and "${QuestionP}. I want to read these files and store each complete line in the respective array,

IFS=$'\r\n' GLOBIGNORE='*' command eval "LinkA=($(cat "${LinkP}"))"
IFS=$'\r\n' GLOBIGNORE='*' command eval "QuestionA=($(cat "${QuestionP}"))"

Now I want to operate on these using a for loop

nLink=${#LinkA[@]} # Size of array
for ((i = 0; i < nLink; i = i + 1)); do
    echo $i
    Question=${QuestionA[i]}
    echo "Question=${QuestionA[i]}"
done

But, the Question variable doesn't contains full line, it breaks after each space character.

How can I store each question and link (complete line in respective file) in these variable and process them inside for loop.

0

1 Answer 1

2

store each complete line in the respective array

is easy with a different approach:

mapfile LinkA < "$LinkP"

See help mapfile for more options, such as -t to remove a trailing delimiter from each line.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .