testing if a file is present

Jonathan Stigelman stig at rabbit.ece.cmu.edu
Mon Nov 26 06:20:06 AEST 1990


There's a one line solution that works with both csh & sh...
and is particularly handy in makefiles.

	[ -f foo ] && mv foo bar || echo foo does not exist

This is a handy way to deal with the yacc tokens file y.tab.h
so that you don't fire lots of extra recompilataions when everything
depends on that tokens file.

	cmp y.tab.h tokens.h && rm y.tab.h || mv y.tab.h tokens.h

Cryptic enough?
Stig



More information about the Comp.unix.shell mailing list