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
    echo "Question=${QuestionA[i]}"

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.


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.