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."