LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-29-2012, 05:04 AM   #1
beckss
Member
 
Registered: Nov 2008
Posts: 39

Rep: Reputation: 0
Using grave accent into rsh script.


Hi gurus!
Can anybody explain me if exist possibility using grave accent with rsh syntax. Here below piece of script ->
[root@noaapp1 ROOT_ACTIVE_CRON]# 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 "
and I recieved error.
bash: -c: line 1: syntax error near unexpected token `do'
bash: -c: line 1: `do'

Thanks and best regards, Staas.
 
Old 05-29-2012, 06:53 AM   #2
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
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 View Post
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.
 
Old 05-29-2012, 07:50 AM   #3
beckss
Member
 
Registered: Nov 2008
Posts: 39

Original Poster
Rep: Reputation: 0
Hi!
Thanks you correct. I am not paste proper code.
Please inpect below ->
[root@noaapp1 tmp]# rsh racdev1 ". .bash_profile;
list_files="1 2 3 4 5 6 7"
for i in `echo ${list_files}`
do
echo $i
sleep 1
done"
bash: line 1: 2: command not found

Thanks Staas.
 
Old 05-29-2012, 08:38 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,790

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
yes, it is the same:
rsh host command
command is now: ". .bash_profile;
list_files="1

described by "some text" and the 1 coming immediately after "
and the following 2 3 4 5 6 .... have no meaning. That's why you got 2: command not found.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
doing a cat on grave accent sjo Linux - Newbie 5 11-10-2010 01:09 AM
SSH Script to replace RSH Script felton57 Linux - Enterprise 2 09-24-2010 10:06 AM
perl script driving me to an early grave mdudu Linux - Server 4 09-16-2009 02:01 AM
Accent grave in ubuntu 8.04 tsp907 Linux - Newbie 1 10-26-2008 11:56 AM
accent grave ague in kde suse 10!! how??? Randall Slack SUSE / openSUSE 6 01-19-2006 12:47 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration