The script is fine. The error you describe most likely means you have Windows-style line endings. I can reproduce it by adding \r
to the end of each line:
$ cat script.sh
if [ -d /etc/nginx ];
then
cp -R /etc/nginx/* /tmp/
fi
$ sed 's/$/\r/' script.sh
$ ksh script.sh
script.sh: syntax error at line 5: `if' unmatched
You probably edited the file on a Windows computer and that would have inserted \r\n
line endings instead of the normal *nix \n
line endings. Just remove them and you should be fine:
sed -i 's/\r//' script.sh
That might not work on AIX's sed
though. If it doesn't, use this instead:
sed 's/\r//' script.sh > tempFile && mv tempFile script.sh
Or
tr -d '\r' < script.sh > tempFile && mv tempFile script.sh
od -c script.sh
or such should tell.