In non-interactive shell, you don't have full jobs control. When you start jobs
in command substitution, it ran in a subshell. In this subshell, there's no jobs running, you got nothing.
In interactive shell, the MONITOR was set, gave you full jobs control. In this case, zsh
store all jobs in a table when you enter a subshell, and will use that job table if there's no jobs in subshell.
With zsh
4.3 and above, you can turn on job control in non-interactive shell by putting -m
on shebang line:
#!/usr/bin/zsh -m
or using setopt
:
setopt monitor
: The rest of script goes here
A better way to check the job state can be:
#!/usr/bin/zsh
zmodload zsh/parameter
babel www/scripts6/lib/data.js > www/scripts/lib/data.js &
babel www/scripts6/lib/user.js > www/scripts/lib/user.js &
babel www/scripts6/lib/profile.js > www/scripts/lib/profile.js &
babel www/scripts6/lib/d3-and-svg.js > www/scripts/lib/d3-and-svg.js &
babel www/scripts6/main.js > www/scripts/main.js &
while (( ${#jobstates} )); do
print "moo"
done
Anyway, you can wait for all child processes with builtin wait:
babel www/scripts6/lib/data.js > www/scripts/lib/data.js &
babel www/scripts6/lib/user.js > www/scripts/lib/user.js &
babel www/scripts6/lib/profile.js > www/scripts/lib/profile.js &
babel www/scripts6/lib/d3-and-svg.js > www/scripts/lib/d3-and-svg.js &
babel www/scripts6/main.js > www/scripts/main.js &
# Wait for all children
wait
echo END
wait
wait
is the proper way to do this and will work both interactively and in a script.