handle pipe termination separately depending on whether a shell is present