while loop in tcsh command line

while loop in tcsh command line

Post by Uwe Pros » Wed, 25 Jul 2001 23:07:48



Hi there,

I am using tcsh and got following problem.

Sometimes it is necessary to wait for a certain file to be written or
erased or wait for another event and execute a command afterwards. This
case happens quite often so I want to use the command line rather than
writing a shell script each time. Normally one would expect the
following line would do what I want:

tcsh# while (-f fileName);sleep 5;end;execute_command

But the shell asks:

while?

If I am typing "end" now the while loop starts but the command
(execute_command) is executed each loop. I could not find a way to wait
for the event and execute the command afterwards by using the command
line.

Using bash one can do this in the command line as expected. Another
possibility would be to write a small script for each case like the
following:
...
while (-f fileName)
   sleep 5
end
execute_command

But I am looking for a way to this in command line not in a script.
Anyone who got an idea?

Thanks.

Uwe

--

 
 
 

while loop in tcsh command line

Post by Keith Thompso » Thu, 26 Jul 2001 13:38:40


[...]

Quote:> tcsh# while (-f fileName);sleep 5;end;execute_command

> But the shell asks:

> while?

> If I am typing "end" now the while loop starts but the command
> (execute_command) is executed each loop. I could not find a way to wait
> for the event and execute the command afterwards by using the command
> line.

tcsh's syntax is not as flexible as bash's.  (More precisely, the
syntax of csh and its derivatives is not as flexible as that of sh and
its derivatives.)

In bash, multi-line constructs can be given on one line by inserting
semicolons.  tcsh doesn't let you do that.

You have to use multiple lines:

tcsh# while (-f fileName)
while? sleep 5
while? end
execute_command

Or you can do something like this:

tcsh# bash -c 'while [ -f fileName ] ; do sleep 5 ; done ; execute_command'

--

San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
Cxiuj via bazo apartenas ni.

 
 
 

while loop in tcsh command line

Post by Uwe Pros » Thu, 26 Jul 2001 15:12:46



> tcsh's syntax is not as flexible as bash's.  (More precisely, the
> syntax of csh and its derivatives is not as flexible as that of sh and
> its derivatives.)

> In bash, multi-line constructs can be given on one line by inserting
> semicolons.  tcsh doesn't let you do that.

I suspected this, but wasn't really sure.

Quote:> Or you can do something like this:

> tcsh# bash -c 'while [ -f fileName ] ; do sleep 5 ; done ; execute_command'

This is a good idea, but the commands I use run only in a tcsh
environment and most of the files are visible in tcsh only. So there are
two possibilities: If it is possible to express the condition in bash
environment I can use

tcsh# bash -c 'while [ -f fileName ] ; do sleep 5 ; done';
execute_command

For all other cases I will try to write a small flexible script, which
takes the condition and maybe the command to execute as a command line
argument.

Thanks.

Uwe

 
 
 

1. Sed loops on the command line in tcsh (was: Re: How to change leading tabs?)

[newsgroups expanded]


This works well in a script, but I have trouble trying to do it from
the command line without a script.  

I tried:

sed ': loop;s/^\(       *\)     /\1  /;t loop' infile

but I get an error message:

Label too long: : loop;s/^\(    *\)     /\1  /;t loop

What am I doing wrong?

I'm using tcsh for my interactive shell.

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.

2. Removable Media Handling...

3. Sed loops on the command line in tcsh (was: How to change leading tabs?)

4. run unix processes as another user ?

5. Accessing command - line parameters in loop

6. A few minutes of your time...

7. loops in an rsh command line how ???

8. what's the use of an LWP ?

9. bourne shell FOR loop - executing a command on each line in a file

10. tcsh's command line editor & vi

11. tcsh and command line editing, display all wacky - how to fix?

12. tcsh's vi command line mode: How to Change Word Delimiter

13. tcsh-command line editing