2

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?

Zanna
  • 70,465

1 Answers1

3

I saw this technique:

read VAR1 VAR2 < path/to/input/file.txt
echo $VAR1
echo $VAR2

Source:

https://stackoverflow.com/questions/29270289/bash-read-from-file-and-store-to-variables

Zanna
  • 70,465
George Udosen
  • 36,677