-1

This question already has an answer here:

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.

marked as duplicate by muru command-line Mar 23 '17 at 8:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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
  • Hi Yaron..I'm not getting any output after running the below script. – Jyothsna Chilukuri Mar 23 '17 at 9:24
  • source=FilePathInfo.properties echo $filepath1 I am getting blank output it means it is not reading values inside FilePathInfo.properties. – Jyothsna Chilukuri Mar 23 '17 at 9:26
  • remove the = from the source command – Yaron Mar 23 '17 at 9:27
  • create Path.property which holds the two lines in my answer, and copy/paste the next 3 lines into shell – Yaron Mar 23 '17 at 9:28
  • If I remove = and renamed to Path.property and getting error as source not found – Jyothsna Chilukuri Mar 23 '17 at 9:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.