Welcome to the most active Linux Forum on the web.
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 07-05-2007, 08:43 AM   #1
Senior Member
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: SlackWare > Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy .. bullseye bookworm
Posts: 1,834

Rep: Reputation: 108Reputation: 108
tcsh How to execute foreach in subshell?


Following is the digest of my code

foreach a ("`cat inputfile`")
++ do some work for each line ++
and I want to pipe entire output into "sort".

I can do
myProgram inputfile | sort
, but I want everything in one shell script for easier maintenance. So I tried to send foreach to subshell
foreach a ("`cat inputfile`")
++ do some work for each line ++
) | sort
and tcsh chokes saying too many ('s.

Question is
How to send foreach to subshell?
Or any other idea?

My tcsh is 6.14.00 Astron 2005-3-15 (Debian etch one)


Happy Penguins!
Old 07-07-2007, 07:10 AM   #2
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 735

Rep: Reputation: 76

In Section 2b of there is the statement:
You can't mix flow-control and commands, like this:

who | while read line; do
echo "gotta $line"
Although tcsh is different from csh, I think most of the pros and cons of csh apply to tcsh.

You may have seen in man tcsh that foreach and end keywords must "appear in a single simple command on an input line".

I'd be interested in hearing if there is a solution to your problem, but I don't think it would lure me into doing much scripting in tcsh.

As you are no doubt weary of hearing: most people use Bourne family shells for scripting ... cheers, makyo


foreach, subshell, tcsh

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
Perl: Where am I in a foreach loop? jrtayloriv Programming 3 01-30-2005 10:43 PM
mc subshell.c: read (subshell_pty...): rickenbacherus Linux - Software 2 07-14-2004 07:14 PM
foreach loops chunky Linux - General 2 07-02-2004 11:49 AM
Continuing a script on a new subshell dpillay Programming 2 05-29-2004 07:26 PM
perl:foreach katana Programming 3 07-24-2001 01:05 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:34 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
Open Source Consulting | Domain Registration