AAA <options>; CCC AAA <options>

AAA, CCC are different commands.

Here we're in an zsh script - for example:

vi script.zsh
AAA <options>; CCC AAA <options>

Verbose: Correct me if I'm wrong, CCC AAA <options>'s AAA <options> will be using a subshell and then create a separated process from current shell or may be using current shell and then create a sub-process from the process that running current script.

The problem is that CCC will stay alive after script.zsh is finished. This causes problem that when I try to call something that as result - not the return value (it did create something after done - a newly created object for i.e) of CCC AAA <options>'s AAA <options> INSIDE script.zsh causing not found warning.

That's being said, how to make current script.zsh can see the result of 'AAA <options>'?

If possible target the Z-shell.

EDIT: Should be:

AAA <options>; CCC AAA <options>
  • what result? standard out? err? both? the exit status code? – thrig Sep 13 '18 at 13:45


CCC 'AAA <options>'

Starts CCC with one literal AAA <options> argument. That's the same in every shell. You can verify by using the echo command in place of CCC:

$ echo 'AAA <options>'
AAA <options>

If you wanted to call CCC with the output (without the trailing newline characters) of AAA as one single argument, you'd do:

CCC "$(AAA <options>)"

If you wanted to call CCC with as many words as there are in the output of AAA (space, tab, newline, NUL separated), you'd do:

CCC $(AAA <options>)

In any case, CCC won't be started until AAA has returned and the script won't terminate until CCC has returned.

For a script to terminate before a command returns, you'd need it to start that command asynchronously like with:

CCC args &

In any case, that's the same in every shell, it's not zsh specific (except for that splitting on NUL above).

| improve this answer | |
  • I edited the 1st post, it's actually AAA <options>; CCC AAA <options> – Tuyen Pham Sep 14 '18 at 10:10
  • I found out that I assumed that CCC AAA <options> had completed and object had been created but that's not true, I had to put while loop to test against the exsiting of the object and wait till it completely created before do other task so the question is why I put the command to process against object after the CCC AAA <options>, zsh shell did not wait till the process to complete to move to next command that make me conclude AAA <options> might run in a sub-process or a separated shell. Is that true? – Tuyen Pham Sep 14 '18 at 10:17
  • @TuyenPham, not sure what you mean AAA <options> starts AAA with <options> as argument in a child process and zsh waits for the child process to return, CCC AAA <options> starts CCC with AAA, <options> as arguments and zsh waits for that process to return. Whether CCC treats its first argument as a command name is not known to zsh. CCC may itself fork child processes that keep running after their parent dies, but again zsh or any other shell would not know nor care about them. – Stéphane Chazelas Sep 14 '18 at 10:31
  • True, zsh seems doesn't care, probably here CCC did a fork process to process AAA <options> and the AAA <options> took longer to process of CCC . That caused the problem. – Tuyen Pham Sep 14 '18 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.