LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 07-05-2007, 09:43 AM   #1
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy jessie
Posts: 1,455

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


Hya,

Following is the digest of my code
Code:
#!/bin/tcsh

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

I can do
Code:
myProgram inputfile | sort
, but I want everything in one shell script for easier maintenance. So I tried to send foreach to subshell
Code:
#!/bin/tcsh
(
foreach a ("`cat inputfile`")
++ do some work for each line ++
end
) | 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)

Thanks

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

Rep: Reputation: 72
Hi.

In Section 2b of http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/ there is the statement:
Quote:
You can't mix flow-control and commands, like this:

who | while read line; do
echo "gotta $line"
done
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
 
  


Reply

Tags
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 11:43 PM
mc subshell.c: read (subshell_pty...): rickenbacherus Linux - Software 2 07-14-2004 08:14 PM
foreach loops chunky Linux - General 2 07-02-2004 12:49 PM
Continuing a script on a new subshell dpillay Programming 2 05-29-2004 08:26 PM
perl:foreach katana Programming 3 07-24-2001 02:05 AM


All times are GMT -5. The time now is 11:19 AM.

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