Bash Array not accepting WildCard

I have an Array that I have setup in a bash script. My goal is to ping through a particular port on a a server with many network interfaces. For example the ping -I eth3 172.26.0.1 command to force ping through eth3

When I setup a bash Array I can get code to work if I call the Elements (ports) individually. For example here I tell it to ping Element 2 or eth5


ethernet[0]='eth3'
ethernet[1]='eth4'
ethernet[2]='eth5'
ethernet[3]='eth6'

ping -c 1 -I ${ethernet[2]} 172.26.0.1


The script works and pings through eth5


[13:49:35] shock:/dumps # bash -x ARRAY
+ ethernet[0]=eth3
+ ethernet[1]=eth4
+ ethernet[2]=eth5
+ ethernet[3]=eth6
+ ping -c 1 -I eth5 172.26.0.1
PING 172.26.0.1 (172.26.0.1) from 172.26.0.192 eth5: 56(84) bytes of data.
From 172.26.0.192 icmp_seq=1 Destination Host Unreachable

--- 172.26.0.1 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 3001ms




However if I use a wildcard instead of just element 2 it dies on the second element (Eth4)

ethernet[0]='eth3'
ethernet[1]='eth4'
ethernet[2]='eth5'
ethernet[3]='eth6'


ping -c 1 -I ${ethernet[*]} 172.26.0.1

[13:48:12] shock:/dumps # bash -x ARRAY
+ ethernet[0]=eth3
+ ethernet[1]=eth4
+ ethernet[2]=eth5
+ ethernet[3]=eth6
+ ping -c 1 -I eth3 eth4 eth5 eth6 172.26.0.1
ping: unknown host eth4



Any thoughts, as to why the wildcard is dying on the second element in the Array? I am new to scripting, I am really just trying to use what I have learned from this article and apply it to a useful networking script. Thanks

http://www.thegeekstuff.com/2010/06/bash-array-tutorial/
langdjAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Christopher Jay WolffWiggle My Legs, OwnerCommented:
Hi.  Also new to this.  Taking a look here makes me think you're only seeing one argument using * instead of @ so it quits.  Could you please try switching to @ and let us know if that does it?  the @ is supposed to be the form of wildcard that preserves the original quantity of arguments.  I found this elsewhere among other differences between * and @ and recommend searching for these differences for detailed explanations.  There are also differences between them depending on how you use double quotes.  So you may need to change...
${Ethernet[@]}

to

"${Ethernet[@]}"
woolmilkporcCommented:
"-I" of "ping" does not accept more than one interface name.
You must loop through the array:

for eth in ${ethernet[*]}; do
   ping -c 1 -I ${eth} 172.26.0.1
done

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
langdjAuthor Commented:
Chris I tried your suggestion but it did not change anything. Good thought though!  

Woolmilkporc. That was the issue! Thanks so much.
langdjAuthor Commented:
Chris I tried your suggestion but it did not change anything. Good thought though!  

Woolmilkporc. That was the issue! Thanks so much.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.