Path: utzoo!attcan!uunet!know!zaphod.mps.ohio-state.edu!usc!snorkelwacker.mit.edu!bloom-beacon!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.shell Subject: Re: testing if a file is present Message-ID: <1990Nov21.191638.19469@athena.mit.edu> Date: 21 Nov 90 19:16:38 GMT References: Sender: daemon@athena.mit.edu (Mr Background) Reply-To: jik@athena.mit.edu (Jonathan I. Kamens) Distribution: comp.unix Organization: Massachusetts Institute of Technology Lines: 38 In article , ger@prisma.cv.ruu.nl (Ger Timmens) writes: |> Can anybody tell me how I can verify |> whether a file exists or not ? |> I want to move files and only when |> they exist ! mv "file" gives an |> error message if "file" not exists It depends on the shell you're using. In csh or tcsh: if (-e filename) then ... stuff if filename exists ... endif In sh, with either a test built-in named "[" or a link in your filesystem called "[" pointing to the test program: if [ -r filename ]; then ... stuff if filename exists ... fi Some versions of test allow "-e" to test for existence, instead of "-r" to test for existence and readibility, but mine doesn't, so I use "-r" instead of "-e" above. In sh without "[": if test -r filename; then ... stuff if filename exists fi Ksh and bash probably do things the same way sh does, using "[". In the future, it would help if you would give more details, such as the shell you're using, when you ask questions like this. -- Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710