0

how can i make a bash script to tell the script this:

i will tell the bash like:

#!/bin/bash
include /usr/local/serverinfo.txt or.sh

rsync -avz $location root@$host:/$location2

all of this $location, $host , $location2, to be entered in /usr/local/serverinfo.txt

how can i tell the bash script to get this infos from the file,

if i put them in the same file will work just perfect, however i whant it to be outside of the file, any ideea?

let me know, thanks.

2 Answers 2

5

You can use source, or equivalently ., which takes another file as an argument and executes it. This assumes that the file you are sourceing contains valid bash syntax.

script.sh:

#!/bin/bash
var=1

source inc.sh          # or . inc.sh
echo $var

inc.sh

var=2

output:

2
Sign up to request clarification or add additional context in comments.

Comments

0

This depends on how the data in serverinfo.txt is formatted. If it is a simple list like

/this/is/the/first/location
/this/is/the/host
/this/is/the/second/location

then you can do

location=$(sed -n '1p' /path/to/serverinfo.txt)
host=$(sed -n '2p' /path/to/serverinfo.txt)
location2=$(sed -n '3p' /path/to/serverinfo.txt)

1 Comment

my ideea is to name like: info=1 ,info2=2, but if your ideea works, i can also set them like 1,2,3,4 it will not be a problem for me.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.