for loop not working on csh tcsh

Using shell csh, which is tcsh 6.21.00:
foreach i ( * ) ; echo $i ; end
However asks:
foreach?

And waits for some input. Any help please?
Noticed that with sh works perfectly:
for i in * ; do echo $i ; done
 
";" is the problem - you will need to use more lines for your script:
Code:
#!/bin/tcsh
foreach VALUE (`some program`)
    echo $VALUE
end
 
Noticed that with sh works perfectly:
General comment: (t)csh and (ba)sh are very different internally. The fact that simple things work the same misleads people into believing that they are compatible. They are not. My personal solution is to use exactly one shell, and about 20 years ago I standardized on bash. Others swear by (pd-) ksh or zsh, and several others. But pick one and get good at it.

Old joke: Beware or the man who has only one gun, because he knows how to use it.
 
";" is the problem - you will need to use more lines for your script:
Code:
#!/bin/tcsh
foreach VALUE (`some program`)
    echo $VALUE
end
Yeah that works if you put that in a file. I guess you can't do it one-liner with tcsh.
 
Maybe not as a one-liner but still very usable interactively.

Code:
dice@molly:~ % foreach f (`seq 1 10`)
foreach? echo $f
foreach? end
1
2
3
4
5
6
7
8
9
10
 
Back
Top