Reputation:
I want to read something from a file and tokenize it into several variables in Bash, but I'm not sure how.
Example:
Enter file path: foo/bar.txt
var1 = 'a'
var2 = 'b'
var3 = 'c'
var4 = 'd'
The contents of bar.txt would simply be "a,b,c,d". It would have to be a one line file. I was thinking of using grep somehow. Is there an easy way of doing this, or am I making things to complicated?
Upvotes: 1
Views: 252
Reputation:
IFS=, read var1 var2 var3 var4 < bar.txt
Set field separator
Set input file
Set resultant variables
Upvotes: 2