Please use
[CODE][/CODE] tags around your code. Here is your command, with color and whitespace added for clarity and emphasis:
Quote:
Originally Posted by beckss
Code:
rsh racdev1 -l oraint "
. .bash_profile;
do
list_files="1 2 3 4 5 6 7"
for i in `echo ${list_files}`
do
echo $i
sleep 1
done "
|
There are so many errors I don't know where to start.
Quoting: After
oraint, you supply 7 parameters to
rsh. The first parameter ends with 1, the second parameter is 2, and so on; the final parameter starts with 7. If you do not understand why this is, read the
Quoting section in the Bash reference manual.
The first
do is an error. There is no reason for it.
Backticks within a double-quoted string: the command within the backticks is run on the current machine, and whatever it yields, is inserted into the double-quoted string before it is given to
rsh. Besides, you should be using
$(...) instead of
`...` (unless the default shell on the remote system is an ancient Unix Bourne shell -- and I don't think so, because you're explicitly sourcing
.bash_profile on the remote machine).
for i in $(echo ${variable});: No, do not do that. It applies pathname expansion twice, and you do not want nor need that. Typical use would be
for i in ${variable};, where the value of
variable will be split and pathname expansion applied, and
i will loop over the results.
Finally, are you sure you wish to use
rsh and not
ssh (with key-based authentication)?
Consider using something like
Code:
ssh -l oraint racdev1 bash -c 'for i in 1 2 3 4 5 6 7; do echo $i; sleep 1; done'
or perhaps
Code:
ssl -l oraint racdev1 bash -c '"list=(1 2 3 4 5 6 7)"'; for i in "${list[@]}" ; do echo "$i" ; sleep 1 ; done'
Both of these execute bash explicitly, just in case the default shell might be something else on the remote machine. The latter uses double quotes to set up the
list array in the remote shell, so you can insert variables etc. from the local shell. The actual snippet is in single quotes, so that the local shell will not interpret that part. Both just echo the numbers 1 to 7 one at a time, sleeping for a second in between, running the loop on the remote machine.