2

I have a problem with a script in AIX, but I can't find the mistake. I want to copy files between two directories but checking first the existence of those directories. What I'm doing is this:

PATH=/home/fede/
PATH2=/home/prueba/
if [ -d $PATH ];
then
find $PATH -type f -exec cp {} $PATH2 \;
        echo "se copiaron los archivos correctamente"
else
        echo "no existe"
fi

But I receive this message: ./scriptTB[5]: find: not found. se copiaron los archivos correctamente. The last line says "The files were copied correctly" in Spanish. The name of the script is scriptTB.

Do I have to put anything before find? It seems that the problem is in find.

4
  • do you mind editing your post to format the code correctly? Simply highlight it, then press the '{}' button in the text box. Thanks Jan 12, 2017 at 17:55
  • 6
    $PATH is a default environment variable which tells your system where to find its program binaries (like the find program you are trying to use), so you should use a different name for that variable. I am betting that you are overwriting your system's $PATH, and now your system cannot find the find program. Try this and see if it works. Jan 12, 2017 at 18:00
  • also if you want to test this and see what I mean, simply open a new terminal and run echo $PATH. Jan 12, 2017 at 18:01
  • 1
    Hey thanks. That was the problema. Thank you !! Do I have to "close" this question?
    – user210129
    Jan 12, 2017 at 18:06

2 Answers 2

4

$PATH is a default environment variable which tells your system where to find its program binaries (like the find program you are trying to use), so you should use a different name for that variable. I am betting that you are overwriting your system's $PATH, and now your system cannot find the find program. Try this and see if it works.

0

PATH happens to be the environment variable used by the shell to locate executables. If you unset it or change it, the shell might not find commands such as find or cp.

It would be better if you used lowercase variable names in scripts. It is less likely that they collide with important environment variables.

In this case, you could use source_dir and target_dir, for example, which have the additional benefit of providing the reader with a bit of documentation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .