2

Is there a way to copy the content of a text file to a variable in Bash?

Let's say I have a file containing some text, and I would like to modify text but not a file itself. How can I copy the content of this file to a variable, and then modify the variable?

Maka
  • 25
  • 5

1 Answers1

3

I'm not very clear on what you're asking, but I think this is what you're after.

if you have file.txt, you can do this

var1=$(cat /path/to/file.txt)

you can then manipulate it how you please.

edit:

You can access the variable by $var1, i.e. echo "$var1"

1ntgr
  • 126
  • 2
  • 8