This is a better phrased and modified version of the question I've posted earlier today (available Load List From Text File To Bash Script).
The goal: be able to load a specific list from domains.txt
file based on an argument passed to the bash script during call.
Text file list structure/format:
Monday_domains=( "google.com" "yahoo.com" .... "amazon.com" )
Tuesday_domains=( "google.com" "msn.com" .... "mozilla.com" )
Wednesday_domains= ( "abc.com" "cnbc.com" .... "NYtimes.com" )
Bash file:
#!/bin/bash
domain=$1 #arg passed
source domains.txt
if [ "$domain" = "1" ]; then
domain_property="$Monday_domains"
elif [ "$domain" = "2" ]; then
domain_property="$Monday_domains"
else
domain_property="$Monday_domains"
fi
counter=0
for i in "${domain_property[@]}"
do
echo "${domain_property[counter]}"
grep "${domain_property[counter]}" domains.log
let counter=counter+1
echo "$counter"
done
echo "$counter"
This script doesn't pass all of the properties (actually just passed one as it didn't cycle through the list in the text file), but I just wanted to demonstrate what I'm looking for. Is it possible to construct a list based on an argument passed? It's important that the list will preserve it's structure, since the rest of the code is configured towards it. I appreciate any input you have, and sorry for double post.... Thank you,