Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 01-11-2012, 01:15 PM   #1
LQ Newbie
Registered: Jan 2012
Posts: 2

Rep: Reputation: Disabled
bourne / csh while differences


I hope this belongs in the "Programming" section (I'm new to LQ)....

I am a junior FreeBSD sysadmin and really like csh (standard shell on our FreeBSD machines). Sometimes the need for a while loop arises. These last couple of weeks I have been forced to do certain stuff in bourne shell because my csh skills are not op to the task. This is a bit cumbersome and frustrating: how difficult can csh's while implementation be ?

I've searched a lot of websites (including LQ) but haven't been able to translate a simple while loop into correct csh syntax. Csh seems a bit elusive


file "kwaak.txt" contains :


I'm able to do stuff for each entry in bourne by issuing:

cat kwaak.txt | while read example ; do echo "Displaying $example" ; done


Displaying a
Displaying b
Displaying c
Displaying 1
Displaying 2
Displaying 3

If I issue the same command while in csh things obviously don't work because of the different syntax that is required by csh. After asking several coworkers and abusing google for quite some time I haven't been able to find the correct csh syntax.

My solution now is to enter a traditional bourne shell and do it there or to write a script that does it; both are not ideal.

Perhaps somebody on this forum can help out?

Any help would be greatly appreciated!


Old 01-11-2012, 05:54 PM   #2
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Hi FuX and welcome to LinuxQuestions!

Reading a file line-by-line is one of the Top 10 reasons not to use the C-shell. Furthermore, you cannot feed a while loop with input from a pipe or from input redirection, since the if/while/foreach construct - and even the read statement - expect the standard input always from outside the script.

Anyway - you're lucky - a simple solution exists:
foreach example (`cat kwaak.txt`)
  echo "Displaying $example"
Hope this helps.
Old 01-17-2012, 05:35 AM   #3
LQ Newbie
Registered: Jan 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Hi colucix,

TnX for your quick and helpfull reply. While your syntax is correct it seems only usable in shell scripts; the thing I wanted to avoid. TnX for the correct syntax though; might prove to be handy in the future

The link/info you provided made me "give up" on csh. I've accepted that for more complex stuff it is not suitable/ideal. I'm currently devising a way to

- log onto our machines and use /bin/sh instead of /bin/csh
- forward my ".shrc" over the ssh-connection to our machines

so that I don't have to work with csh anymore.

Thank you for your help!




csh, loop

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
[SOLVED] Getting the Bourne again Shell drmjh Linux - General 16 07-03-2011 07:23 AM
sh, Bourne problem kdyzsa Programming 5 05-09-2008 07:59 PM
Bourne and Decimals? kdyzsa Programming 4 05-07-2008 02:16 AM
bourne vs bash alaios Linux - Software 2 03-13-2004 01:16 AM
Bourne Again SHell help MagInnovision Linux - Newbie 2 02-04-2003 04:43 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:25 PM.

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