I'm trying to loop same variables from multiple files in bash. Here's my file structure and their contents;
- script.sh
- first.conf
- second.conf
Inside of first.conf;
var=Hello1
Inside of second.conf;
var=Hello2
Inside of script.sh;
#!/bin/bash
_a=`find ~/ -name "*.conf"`
source ${_a}
for x in ${_a}
do
echo "$var"
done
This might look really dumb tho, I'm really new to programming.
What I'm trying to do is to loop and echo these $vars from 2 different configs.
How can I do that?
findin a single string isn't always a great idea in and of itself. Look at what happens when your filenames have spaces, or -- even worse -- if the files contain newlines.findreturns multiple results; an array is the native approach to storing several strings in bash (and using NUL rather than newline delimiters lets you distinguish between newlines added as separators byfindand newlines that are part of the filenames themselves).