How can I read a variables file into a bash script? [duplicate]
By John Peck •
I'm creating bash scripts to copy files search errors etc. from all our test servers.
I want to create an input file for these servers because they’re all test systems so they change hostname and IP from time to time.
Currently, I have to change all scripts if a server is changed.
I want one input file so I only have to change it there. So I only have to change the input file.
My input file I have created looks like this:
#!/bin/bash
SERVER1=$(echo "node1.example.com")
SERVER2=$(echo "node2.example.com")
etc.I have tried
export file="path/to/input/file"and also
read file="path/to/input/file"but it doesn't work.
Now I want to read the values $SERVER1, $SERVER2, etc. into my other scripts.
How can I do that?
11 Answer
I saw this technique:
read VAR1 VAR2 < path/to/input/file.txt
echo $VAR1
echo $VAR2Source: