Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

rsh script with inside a for loop

Shell Programming and Scripting


Tags
shell script, shell scripting, unix scripting, unix scripting basics

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-19-2006   -   Original Discussion by trekianov
trekianov's Unix or Linux Image
trekianov trekianov is offline
Registered User
 
Join Date: Jan 2006
Last Activity: 25 January 2006, 4:45 AM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
rsh script with inside a for loop

hi everyone,
I have the following problem: the foreach loop inside rsh doesn'work.
I have tried the for command but it's not recognized. with the foreach command I don't receive any error, but it doesn't really make the cycle, ignoring the foreach and executing 1 time the echo command. Anyone has ideas?

rsh host "cd a/b
exe<< stop
1
2
stop
exe2<<stop2
a
b
stop2
foreach ptcluster (30 35 40 45 50)
echo PTCLUS=$ptcluster
end
"

I have read read the following statement, but I don't know if it is the real issue:
"When this command is read from the terminal, the loop is read once prompting with `foreach? ' (or prompt2) before any statements in the loop are executed. If you make a mistake typing in a loop at the terminal you can rub it out."
Sponsored Links
    #2  
Old Unix and Linux 01-19-2006   -   Original Discussion by trekianov
kduffin's Unix or Linux Image
kduffin kduffin is offline Forum Advisor  
UN1X
 
Join Date: Nov 2003
Last Activity: 29 June 2017, 11:12 AM EDT
Location: Wandering the world
Posts: 484
Thanks: 0
Thanked 3 Times in 2 Posts
It's always good to try searches before asking. This was discussed a few days ago. Check here.

Cheers,

Keith
Sponsored Links
    #3  
Old Unix and Linux 01-20-2006   -   Original Discussion by trekianov
trekianov's Unix or Linux Image
trekianov trekianov is offline
Registered User
 
Join Date: Jan 2006
Last Activity: 25 January 2006, 4:45 AM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
suggestion

hi, thank you for the suggestion, but the thread you have pointed out is quite different from my issue:
I want to perform a loop inside the compound command. in any case I have tried the suggestion, but didn't worked.
Cheers Michele
    #4  
Old Unix and Linux 01-20-2006   -   Original Discussion by trekianov
Perderabo's Unix or Linux Image
Perderabo Perderabo is offline Forum Advisor  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 26 February 2016, 12:31 PM EST
Location: Ashburn, Virginia
Posts: 9,930
Thanks: 64
Thanked 471 Times in 271 Posts
For one thing, try this:
$ xyz=hello
$ echo "xyz = $xyz"
xyz = hello
$
Shells look inside double quoted strings and replace variables. Your variable $ptscluster will be replaced before your local shell even locates the rsh command. This doesn't explain why you're not looping, but I'm not a csh expert. You should put scripts in an executable file, not in an argument to a command line. Once you use something like "rsh host ./remoteloop", all of the problems will vanish. Make sure you have a line like "#! /usr/bin/csh" in your remoteloop file. Note that you can create remoteloop locally, rcp it into place, chmod it, run it, and then remove it.
Sponsored Links
    #5  
Old Unix and Linux 01-20-2006   -   Original Discussion by trekianov
trekianov's Unix or Linux Image
trekianov trekianov is offline
Registered User
 
Join Date: Jan 2006
Last Activity: 25 January 2006, 4:45 AM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
I have tried this workaround (even if I see it as a defiance :-) ).
but another problem arised: i want to keep the control in the main script of the variable to be passed so I would like to pass them to the script.
this is the "inner" script:
#!/bin/sh
# loop through a set of numbers
# echo $pt
echo nome$1
echo pt$2
echo eta$3
for i in 1 2 ;
do ../herlib/hwuser<<stop ;
$1
$2 $3
$i
stop

done

when I do
$ ./forloop a b c
it works but when it is called by another script it fails to recognize the variables.
for example: I call the previous script (forloop) through
name=tt_25_5_0jet
pt=20
eta=0.6
./forloop<<stop
$name
$pt
$eta
stop

but don't work... any idea?
THANKS in advance Michele
Sponsored Links
    #6  
Old Unix and Linux 12-06-2008   -   Original Discussion by trekianov
lahiru's Unix or Linux Image
lahiru lahiru is offline
Registered User
 
Join Date: Nov 2008
Last Activity: 18 March 2009, 2:08 AM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Use -n with rsh command & then you'r probelem will surely get solve.

EG: rsh host -n "cd a/b


Regards,
Lahiru Jeewantha


Quote:
Originally Posted by trekianov View Post
hi everyone,
I have the following problem: the foreach loop inside rsh doesn'work.
I have tried the for command but it's not recognized. with the foreach command I don't receive any error, but it doesn't really make the cycle, ignoring the foreach and executing 1 time the echo command. Anyone has ideas?

rsh host "cd a/b
exe<< stop
1
2
stop
exe2<<stop2
a
b
stop2
foreach ptcluster (30 35 40 45 50)
echo PTCLUS=$ptcluster
end
"

I have read read the following statement, but I don't know if it is the real issue:
"When this command is read from the terminal, the loop is read once prompting with `foreach? ' (or prompt2) before any statements in the loop are executed. If you make a mistake typing in a loop at the terminal you can rub it out."
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem passing a search pattern to AWK inside a script loop quinestor Shell Programming and Scripting 14 03-14-2012 12:12 PM
help in running while loop inside a shell script rkrish Shell Programming and Scripting 11 11-17-2011 06:03 AM
If inside while loop script error vivek1489 Shell Programming and Scripting 9 06-24-2011 06:35 AM
How to give a variable output name in a shell script inside a for loop alice06 Shell Programming and Scripting 1 10-23-2010 12:16 AM
Using variables created sequentially in a loop while still inside of the loop [bash] DeCoTwc Shell Programming and Scripting 2 06-23-2009 05:59 PM



All times are GMT -4. The time now is 12:06 PM.