Dimitris Delis Dimitris Delis - 1 year ago 73
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

Answer Source

Try something like this :

var=$(cat $1)

then var will contain the content of your file

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download