Below script runs fine on all Servers in my infrastructure.

However, I recently discovered that it fails to complete execution and simply hangs on Aix servers with ksh shell.

cat myscript.sh
export LOG="./test.log"
echo "Starting"
exec >$LOG 2>&1
echo "Completed"

Below is how i have run this script

user1@myhost# . /app/myscript.sh
Output: Starting
<hangs here>

I want this script to run on on different types on OS like AiX, Solaris and Linux.

Note: This script is placed and executed from a remote server that we use for automation. The script hangs when executed remotely using ssh as well as when executed locally as shown above.

Can you propose a generic solution please?

  • 2
    Does the output "Completed" appear in test.log? The script works as expected on Ubuntu Linux with bash and ksh, and there is no obvious reason why it shouldn't work on AIX. Can you reproduce the problem with exactly the script shown in your question or is your real script different? If different, show the real script or create a minimal reproducible example . Please edit your question to add this information, don't use comments to answer.
    – Bodo
    Sep 19, 2020 at 8:45
  • You should change line exec >$LOG 2>&1 into someactualprogram >$LOG 2>&1 Sep 21, 2020 at 6:45
  • @Lorinczy that wouldn't stop the script appearing to hang Sep 21, 2020 at 7:21
  • @roaima Here is an example for myscript.sh export LOG="./test.log"; echo "Starting"; id >$LOG 2>&1; echo "Completed" Sep 21, 2020 at 14:35
  • @LorinczyZsigmond that's totally different Sep 21, 2020 at 14:41

1 Answer 1


Your . command has included the script contents verbatim into your current shell session. One of the lines redirects stdout and stderr, so this is applied to your current shell. It hasn't hung; it's just not showing you anything.

Generally, . is not how to run a script. Instead, make it executable, add a #! line at the top to identify the shell that's to be used to execute it, and call it as /app/myscript.sh (without the . command)

  • post your suggestion it does not print echo "Competed". So the problem persists.
    – Ashar
    Sep 19, 2020 at 10:40
  • It does. Just not to the screen, because you have redirected stdout and stderr Sep 19, 2020 at 12:11

You must log in to answer this question.

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