I have a small piece of code that I want to process a list of paths in a configuration file. In the script I'm appending the paths to a variable. Using [tt]echo[/tt] statements, I can see that the variable has the right value inside of the loop, but it loses its value after the loop.
When I use a piece of code that is similar, but doesn't read the configuration file, I don't have the problem.
What am I doing wrong?
Output:
Config file:
Thank you.
--
-- Ghodmode
Give a man a fish and he'll come back to buy more... Teach a man to fish and you're out of business.
When I use a piece of code that is similar, but doesn't read the configuration file, I don't have the problem.
What am I doing wrong?
Code:
#!/bin/bash
grep -i "^backuppath" backup_config | cut -d: -f2 | tr -d " \t" | while read PATHENTRY; do
BACKUPPATHS="$BACKUPPATHS $PATHENTRY"
echo "Backup Paths: $BACKUPPATHS"
done
echo "Backup Paths: $BACKUPPATHS"[/tt]
Output:
Code:
Backup Paths: /usr/local/mysql
Backup Paths: /usr/local/mysql /etc/my.cnf
Backup Paths: /usr/local/mysql /etc/my.cnf /usr/local/apache2
Backup Paths: /usr/local/mysql /etc/my.cnf /usr/local/apache2 /usr/local/lib/php.ini
Backup Paths: /usr/local/mysql /etc/my.cnf /usr/local/apache2 /usr/local/lib/php.ini /usr/local/tomcat
Backup Paths: /usr/local/mysql /etc/my.cnf /usr/local/apache2 /usr/local/lib/php.ini /usr/local/tomcat /usr/lib/oracle/xe/oradata
Backup Paths:
Config file:
Code:
backuppath :/usr/local/mysql
backuppath :/etc/my.cnf
backuppath :/usr/local/apache2
backuppath :/usr/local/lib/php.ini
backuppath :/usr/local/tomcat
backuppath :/usr/lib/oracle/xe/oradata
Thank you.
--
-- Ghodmode
Give a man a fish and he'll come back to buy more... Teach a man to fish and you're out of business.