Dimitris Delis Dimitris Delis - 8 days ago 6x
Bash Question

Reading a text file into a variable in shell script

Hello I'm trying to save a text file(let's call it file.dat (it's a UTF-8 Unicode text) into a variable in a script I'm making. I want to call the file.dat like : ./myscript file.dat (or something similar).
Having a command line in code in the form of variable=file.dat won't help.

I'm new to shell so I apologize if the question is not very specific


Try something like this :

var=$(cat $1)

then var will contain the content of your file