-1

My FilePath.property file is as below.

filepath1 = /var/log/Test
filepath2 = /home/Backups

I want to read this FilePath.property file inside my shell script and use filepath1 and filepath2 in my script for deleting old logs inside the Test and Backups folders.

Zanna
  • 70,465

1 Answers1

1

The content of Path.property should not include spaces before/after the = sign.

filepath1=/var/log/Test
filepath2=/home/Backups

The following script will print the value of the variables:

source Path.property
echo $filepath1
echo $filepath2

You can replace the echo with mv ,rm commands, etc.

It works like that:

Variable file

$ cat Path.property

filepath1=/var/log/Test
filepath2=/home/Backups

Script file

$ cat printvar.sh

#!/bin/bash
source Path.property
echo $filepath1
echo $filepath2    

execution of the script

$ bash printvar.sh 

/var/log/Test
/home/Backups
Yaron
  • 13,173