# for loop not working on csh tcsh



## bugzeo (Jul 30, 2021)

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`


----------



## jmos (Jul 30, 2021)

";" is the problem - you will need to use more lines for your script:

```
#!/bin/tcsh
foreach VALUE (`some program`)
    echo $VALUE
end
```


----------



## ralphbsz (Jul 30, 2021)

bugzeo said:


> 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.


----------



## SirDice (Jul 30, 2021)

tcsh(1) is great for interactive use, it's not that good to write scripts with. For scripts you should really use sh(1).


----------



## bugzeo (Jul 31, 2021)

jmos said:


> ";" is the problem - you will need to use more lines for your script:
> 
> ```
> #!/bin/tcsh
> ...


Yeah that works if you put that in a file. I guess you can't do it one-liner with tcsh.


----------



## SirDice (Jul 31, 2021)

Maybe not as a one-liner but still very usable interactively.


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


----------

