The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Checking condition inside the loop ithirak17 Shell Programming and Scripting 1 03-13-2008 08:37 AM
remsh inside of while loop joettacm UNIX for Advanced & Expert Users 1 12-07-2007 12:54 PM
Repetitive Tasks: using if..then inside a loop garak Shell Programming and Scripting 2 03-13-2006 07:36 AM
input inside while read loop jhansrod Shell Programming and Scripting 3 08-13-2005 10:46 AM
read inside a while loop dta4316 UNIX for Dummies Questions & Answers 3 05-21-2005 10:53 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-19-2006
trekianov trekianov is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 3
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."
  #2 (permalink)  
Old 01-19-2006
kduffin's Avatar
kduffin kduffin is offline Forum Advisor  
UN1X
  
 

Join Date: Nov 2003
Location: Maryland
Posts: 449
It's always good to try searches before asking. This was discussed a few days ago. Check here.

Cheers,

Keith
  #3 (permalink)  
Old 01-20-2006
trekianov trekianov is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 3
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 (permalink)  
Old 01-20-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,115
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.
  #5 (permalink)  
Old 01-20-2006
trekianov trekianov is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 3
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
  #6 (permalink)  
Old 12-06-2008
lahiru lahiru is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 4
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."
Closed Thread

Bookmarks

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0