[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bash guru wanted



Once upon a time Michael Naumann said...
> 
> >>I want my bash to obey eof (^D) only if there are no jobs in the background.

You can do it with the variable PROMPT_COMMAND. Its value is executed
prior to each prompt.

eg.

function job_test {
  if [ -z "$(jobs)" ] ; then
    set +o ignoreeof
  else
    set -o ignoreeof
  fi
}

PROMPT_COMMAND=job_test

This works with one slight glitch. The order of operations seems to be
1) run PROMPT_COMMAND
2) bash checks for completed jobs
3) print the prompt

This means on the first prompt after the last job exits, the job_test
function still sees the job and sets ignoreeof. On the next prompt (ie.
just press enter, or ^D), it will exit correctly.




Reply to: