0

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,

Community
  • 1
  • 1
Simply_me
  • 2,840
  • 4
  • 19
  • 27

1 Answers1

2

If you want to copy an array, you must do it The Right Way

$ foo=(a b c)

$ bar=( ${foo[*]} )

$ echo ${bar[1]}
b
Zombo
  • 1
  • 62
  • 391
  • 407
  • @Steven_Penny thank you for the answer those brackets always get me. Quick question, do you know if it's possible to source more than one file? I can't find any documentation of it. – Simply_me May 01 '13 at 23:41
  • 1
    @Simply_Me as separate commands yes http://github.com/svnpenn/dotfiles/blob/master/.bash_profile – Zombo May 02 '13 at 00:26