help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] Odd behaviour using $(...)


From: Peter West
Subject: [Help-bash] Odd behaviour using $(...)
Date: Wed, 22 Apr 2015 16:11:29 +1000

The following script, called as ’tiktst’, executes as expected when invoked 
directly from the shell.
———————————————————————————————
#! /bin/sh
TIKA_APP=${TIKA_APP:="$JARS/tika-app.jar"}

typeset -i port=45000

msg () { echo Using port $port; }

pid () { echo Server PID $!; }

case $(basename $0) in
    tiktst)
        msg; java -jar "$TIKA_APP" --detect --server $port & pid ;;
    *)
        echo "Server not executed. Program name not known." >&2 ;;
esac

echo Exited from case statement
exit 0
——————————————————————————————-

Here’s the output:
$ tiktst
Using port 45000
Server PID 11899
Exited from case statement


However, if I try to capture the output like so:
$ res=$(tiktst)

the shell hangs. At this point, the shell in which I have executed this 
statement has no children, and the java process is a child of init.  I can type 
commands, which echo to the terminal, but do not execute, until I kill the java 
process, whereupon they will execute.

If I ’set -x’ I will see all of the commands in debug output, including the 
final ‘exit 0’ and the java command.  If I put ’sleep 2’ after the java 
invocation, I see the java command in the dubug output before the ‘exit 0’; 
otherwise the java command is echoed to debug after the exit 0.

What’s going on?

OS X 10.10.3 bash 3.2.57(1)

Peter West
"Why do you seek the living among the dead? He is not here, but has risen."




reply via email to

[Prev in Thread] Current Thread [Next in Thread]