background foreach in csh or for in sh?

Phil Howard KA9WGN phil at ux1.cso.uiuc.edu
Tue Mar 26 09:18:24 AEST 1991


gwoho at nntp-server.caltech.edu (g liu) writes:

>how do i do a foreach or for in the background without
>writing a script file or explicitly running a new shell
>or something complicated like that??
>is there a simple way to do it?

>gwoho liu.

Is it that complicated to run a new shell?  I assume you are using csh.
Use the "-f" option to supress ".cshrc" execution for faster startup of
the subshell.

echo 'foreach number ( 0 1 2 3 4 5 6 7 8 9 )\
echo the number is $number\
end' | csh -f &

Note that you MUST use SINGLE quotes here, NOT double quotes.  The reason
is because a double quote will allow the $number variable to be interpreted
in your command level shell, and it is either undefined or won't have what
you want in it.  The backslashes are to put newlines into the data echoed
by the first echo.  When I do these types of things, I FIRST test the echo
data by NOT piping it into the subshell:

echo 'foreach number ( 0 1 2 3 4 5 6 7 8 9 )\
echo the number is $number\
end'

Then when I decide I did it right, I type this:

!! | csh -f &

and it will take off.
-- 
 /***************************************************************************\
/ Phil Howard -- KA9WGN -- phil at ux1.cso.uiuc.edu                              \
\ Lietuva laisva -- Brivu Latviju -- Eesti vabaks                             /
 \***************************************************************************/



More information about the Comp.unix.questions mailing list