"Iterate array using loop over ssh"

Post #302831895 by rajamadhavan on Friday 12th of July 2013 05:50:45 AM

I think, this is expected.

When your commands go to server, all the variables are replaced by its values.
The 'echo '${test1[$m]}' at the end of your command is evaluated by your local system (the first element of the array since it cannot make out what $m is) and would be replaced by 'test1' by the time it reaches the server . So it prints the same for all the iterations.
This User Gave Thanks to rajamadhavan For This Post:
 
UNIX and Linux Facts

Unix (trademarked as the UNIX certification mark) is a very mature family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix. Unix development starting in the 1970s by legendary Bell Labs programmers Ken Thompson, Dennis Ritchie, and others. Unix was first targetted for the Bell System and AT&T licensed Unix to outside parties. In the 1970s time period, this lead to a variety of for-profit as well as not-for-profit Unix variants. In the early days, this included the University of California, Berkeley (BSD), Microsoft (Xenix), IBM (AIX), and Sun Microsystems (Solaris). In the early 1990s AT&T sold their Unix rights to Novell. In 1995 Novell sold their Unix business to the Santa Cruz Operation (SCO). The UNIX trademark was passed to The Open Group, a "neutral" industry consortium. The Open Group promoted the use of the UNIX trademark for certified operating systems that comply with the Single UNIX Specification (SUS). In 2014 Apple's macOS became the Unix version with the largest global install base and macOS remains the largest Unix-user base today.
Linux is a family of open source Unix-like operating systems based on the Linux kernel. The Linux kernal is an operating system kernel first released by Linus Torvalds on 17 September 1991. Linux distributions include the Linux kernel, system software and libraries. Popular Linux distributions include Debian, Fedora, and Ubuntu. Commercial Linux distributions include Red Hat Enterprise Linux and SUSE Linux Enterprise Server. Linux is freely redistributable. Anyone may create a Linux distribution for any purpose.
Related Linux and UNIX Technical Support
iterate over array
IMTheNachoMan
I can not for the life of me figure out how to iterate over this array { 'name1' => { 'a' => . 'b' => }, 'name2' => { 'a' => . 'b' => } } I want a for loop to iterate through the first element (name1 and name2 in my example) but I can't figure it out. Help...... Shell Programming and Scripting
2
Shell Programming and Scripting
How to loop(Iterate) through List with foreach(csh)
eawedat
Hey all,, I know cshell is harmful:) but I am using this just "to know" - for educational purposes!... not for a long-term use. lets say i have a list.. set arr=(x y z e f) I wanna iterate the list with foreach ,, not with while.!! foreach i $arr echo $i end does not work... Shell Programming and Scripting
2
Shell Programming and Scripting
Iterate/Loop Through XML Node List
bradlecat
I need to load an XML file and loop through a list of nodes in it to execute a shell script for each one using the attributes for each node as parameters for the script. Any ideas? Any help will be much appreciated.... UNIX for Dummies Questions & Answers
1
UNIX for Dummies Questions & Answers
Do loop doesn't iterate
asandy1234
I'm trying to send the file list as parameter to another job and execute it. But the loop doesn't work, the inner job is running only once and not twice as expected for filelist in $(ls -rt *.txt | tail -2) do echo $filelist export filelist cmd="$Program -config $configfile -autoexec...... Shell Programming and Scripting
11
Shell Programming and Scripting
Ssh to an array of servers in a for loop
Sree10
There are 4 remote hosts that I have stored in an array. A ssh trust has been created from the local host to each of the remote hosts. I am trying to ssh to each of the servers in a for loop as shown below. declare -a host host}]="server1" host}]="server2" host}]="server3" ...... Shell Programming and Scripting
9
Shell Programming and Scripting