0

I have an AWS access file which contains 2 lines.

I'm trying to save its content into a variable, but it always store only the last line..

accessKeyFile=$(cat "$awsAccessKeyPath");
echo $accessKeyFile;

How can I store the whole file content in the variable?

Claudio
  • 10,614
  • 4
  • 31
  • 71
Asaf Nevo
  • 11,338
  • 23
  • 79
  • 154
  • 2
    your solution looks ok, except that you might really want `echo "$var"`. Has your keyFile passed thru MS Windows? if so, fix the line endings with `dos2unix "$awsAccessKeyPath"`. Good luck. – shellter Nov 23 '15 at 15:20
  • 3
    Possible duplicate of [How do I preserve line breaks when storing a command output to a variable in bash?](http://stackoverflow.com/questions/22101778/how-do-i-preserve-line-breaks-when-storing-a-command-output-to-a-variable-in-bas) – tripleee Nov 23 '15 at 15:34

1 Answers1

-1

Try this:

#!/bin/bash
for i in $(cat file.txt); do
    accessKeyFile=$(echo $i)
    echo $accessKeyFile

done    

So you can save whole lines into accessKeyFile