LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   foreach? for one line in tcsh (https://www.linuxquestions.org/questions/linux-desktop-74/foreach-for-one-line-in-tcsh-4175473202/)

Jykke 08-13-2013 02:01 AM

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?

colucix 08-13-2013 02:10 AM

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.

SAbhi 08-13-2013 02:18 AM

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


Jykke 08-13-2013 02:34 AM

well easier to settle for writing the short script then - funny though


All times are GMT -5. The time now is 09:08 PM.