How to do <cmd> file | hold file

Barton E. Schaefer schaefer at ogicse.ogi.edu
Mon Sep 10 03:53:48 AEST 1990


In article <8147:Sep903:14:3990 at kramden.acf.nyu.edu> brnstnd at kramden.acf.nyu.edu (Dan Bernstein) writes:
} In article <1990Sep8.054623.3822 at sj.ate.slb.com> fabrice at sj.ate.slb.com writes:
} > 	alias apply  \!\* \> /tmp/apply.\$\$ \; cp /tmp/apply.\$\$ \!\$
} 
} Much better is
} 
}   % alias transform '(rm \!:1;\!:2* > \!:1) < \!:1'

Of course, if you WANT to put the file name at the end rather than at
the beginning, you can use (sticking with the original alias name):

    % alias apply '( rm \!:$ ; \!:1- > \!:$ ) < \!:$'

but I agree that listing the file first is clearer.

The one problem I see with this is that there ought to be a way to abort
if the rm doesn't happen.  E.g.,

    % transform foo.c grep -v '^/\*###'
    rm: override protection 444 for foo.c?

Unfortunately, no matter what answer is given to this question, "rm"
exits with status 0.  In this particular case the grep command will
fail (on an "n" response) due to lack of write permission on foo.c,
but there are other cases where a problem might occur if the file isn't
rm'd.

Using "mv" would solve this problem, but requires a decision of where
to move the file.
-- 
Bart Schaefer						schaefer at cse.ogi.edu



More information about the Comp.unix.shell mailing list