LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices

Reply
 
Search this Thread
Old 08-13-2013, 02:01 AM   #1
Jykke
Member
 
Registered: Sep 2005
Posts: 166

Rep: Reputation: 16
foreach? for one line in tcsh


I've seen few examples about the foreach in tcsh, all of them
are broken to a script and over more lines. I wanted to execute the
stuff as a handy one liner but I get as an output
foreach?

so what gives?

As a shell script this works:
Code:
#!/bin/tcsh
foreach x ( 1 2 3 )
   echo $x
end
As a one liner this prompts "foreach?"
Code:
foreach x ( 1 2 3 );echo $x;end
Where is the mistake?
 
Old 08-13-2013, 02:10 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
You can't put foreach and the end keywords on one line. This is clearly stated from the man page:
Quote:
Both foreach and end must appear alone on separate lines... When this command is read from the terminal, the loop is read once prompting with ‘foreach?’ (or prompt2) before any statements in the loop are executed.
 
Old 08-13-2013, 02:18 AM   #3
SAbhi
Member
 
Registered: Aug 2009
Location: Bangaluru, India
Distribution: CentOS 6.5, SuSE SLED/ SLES 10.2 SP2 /11.2, Fedora 11/16
Posts: 516

Rep: Reputation: 58
Quote:
foreach x ( 1 2 3 );echo $x;end
";" here is the mistake, in tcsh ";" wil not work as in bash.
dont know much about 'tcsh' but you can try something like this; may or may not work did'nt tested it:

Code:
alias command '(echo "for x (1 2 3)"; echo "$x"; echo "end";)'|tcsh
command

Last edited by SAbhi; 08-13-2013 at 02:19 AM.
 
Old 08-13-2013, 02:34 AM   #4
Jykke
Member
 
Registered: Sep 2005
Posts: 166

Original Poster
Rep: Reputation: 16
well easier to settle for writing the short script then - funny though
 
  


Reply


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
Need a bit of help in line-editing awk\sed and foreach Jykke Linux - General 12 10-14-2010 08:17 PM
tcsh How to execute foreach in subshell? kaz2100 Programming 1 07-07-2007 07:10 AM
How to use foreach on filenames with spaces? BrianK Linux - General 3 08-09-2005 12:15 PM
foreach loops chunky Linux - General 2 07-02-2004 11:49 AM
perl:foreach katana Programming 3 07-24-2001 01:05 AM


All times are GMT -5. The time now is 02:54 AM.

Main Menu
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