Just to give some context, I'm trying to run this command

echo "set hive.execution.engine=tez;" | hive

hive terminates as soon as "set hive.execution.engine..." has been entered into the hive interactive shell,

I want to it to stay in the hive interactive shell, but the shell then terminates and I'm back into the normal linux shell.

3 Answers 3


After the echo finishes, the input of hive hits end of file, so hive terminates. You will probably get the same effect if you hit Ctrl-D in the interactive shell. Try the following:

(echo "set hive.execution.engine=tez;" ; cat ) | hive

However, you may lose cursor movement and other nice features of the interactive shell.

Edit: a better way is probably to put your set command in ~/.hiverc per the hive docs.

  • That's perfect!, worked just as I intended, thanks for your help!
    – Fil
    Sep 10, 2015 at 10:53

It quits as soon as its input ends. So just don't end it:

echo "set hive.execution.engine=tez;" | cat - /dev/tty | hive

You won't lose any features which wouldn't be there anyway. This works by concatenating cat's stdin (which is echo's stdout) with the input from your terminal. It's pretty simple. The other cat solution here will work the same way as long as you run it from a top-level interactive shell.

  • That works as well, thanks for your help. I'll use this answer as I don't want to leave features.
    – Fil
    Sep 10, 2015 at 10:54

I am not sure if the following will be of any help, but just in case, it does, I did a little research.

It can be implemented as (not applied on your command)

if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {

But as for signal, it is deprecated.

Better may be

struct sigaction sa;
sa.sa_handler = SIG_IGN;
sa.sa_flags = 0;
if (sigaction(SIGPIPE, &sa, 0) == -1) {

Source and further information:
Prevent a process from terminating when writing to a broken pipe and
Ignore SIGPIPE without affecting other threads in a process

  • It answers another question: how to prevent pipe terminate the first process? Sep 10, 2015 at 13:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .