[comp.unix.shell] pipes within a script

pfalstad@phoenix.Princeton.EDU (Paul John Falstad) (10/03/90)

In article <1263@umvlsi.ecs.umass.edu> breck@umvlsi.ecs.umass.edu (Liam Breck)
writes:
>I'm trying to write a C shell script in which I step through a bunch

Ah, there's your problem.  csh is horrible for shell scripts.  Use sh or ksh.

>#
>foreach dir (~/tex/ ~/tax/)
>   foreach file_ext (.aux .dvi .log .toc)
>      nohup echo $dir*$file_ext
>      end
>   end
>| rm

You can't do this in csh, as far as I know.  Even if you can, you should
use a /bin/sh script like this:

#! /bin/sh
rm `for dir in $HOME/tex/ $HOME/tax/; do
	for ext in .aux .dvi .log .toc; do
		echo $dir*$file_ext
	done
done | grep -v \\\*`

or else:

#! /bin/sh
for dir in $HOME/tex/ $HOME/tax/; do
	for ext in .aux .dvi .log .toc; do
		echo $dir*$file_ext
	done
done | grep -v \\\* | xargs rm

If you must use csh, do something like:

set nonomatch
echo {~/tex/,~/tax/,~/foo/}*.{aux,dvi,log,toc} | grep -v \\\* | xargs rm

or

set nonomatch
rm `echo { ... } | grep -v \\\*`

What was the nohup for, may I ask?

-----
Here is the address to complain to:
pfalstad@phoenix.princeton.edu PLink:HYPNOS GEnie:P.FALSTAD CIS: 70016,1355
That address again,
sync@thumper.princeton.edu PLink:OHS738 GEnie:OHS738 CIS: 4128 143 1234 937

pfalstad@spot.Princeton.EDU (Paul John Falstad) (10/03/90)

In article <3022@idunno.Princeton.EDU> I write:
>set nonomatch
>echo {~/tex/,~/tax/,~/foo/}*.{aux,dvi,log,toc} | grep -v \\\* | xargs rm
>
>or
>
>set nonomatch
>rm `echo { ... } | grep -v \\\*`

Oops, that's not all necessary.

rm {~/tex,~/tax,~/foo}/*.{aux,dvi,log,toc}

Someone pointed that out to me in email.  I thought csh would give a
'no match' if you did "ls *.c *.aosfdji" if it found some .c files but no
.aosfdji files.

If this is all the original poster wanted to do, this is much better
than the sh script.  I thought it was just an example.

(csh programming still sucks though)

Here is the address to complain to:
pfalstad@phoenix.princeton.edu PLink:HYPNOS GEnie:P.FALSTAD CIS: 70016,1355
That address again,
sync@thumper.princeton.edu PLink:OHS738 GEnie:OHS738 CIS: 4128 143 1234 937