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.

  • do you mind editing your post to format the code correctly? Simply highlight it, then press the '{}' button in the text box. Thanks – user5359531 Jan 12 '17 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. – user5359531 Jan 12 '17 at 18:00
  • also if you want to test this and see what I mean, simply open a new terminal and run echo $PATH. – user5359531 Jan 12 '17 at 18:01
  • 1
    Hey thanks. That was the problema. Thank you !! Do I have to "close" this question? – fedeemp Jan 12 '17 at 18:06
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.

| improve this answer | |
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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.