0

I need to perform a Bash function in the background. The function does some things, prints out its output at specified location on screen, and exits.

function foo(){
  #Do things
  tput cup 10 13
  echo -e "OUTPUT"
}

I had no issues running it in the background, or with nohup description output, but not both. I need to run this function only in background without any output other than the function itselfs.

I have tried playing around with nohup, disown, and &, but without any luck.

kukus888
  • 1
  • 1
  • `foo &` works in background, for example `bash -c 'function foo() { tput cup 10 13; echo -e OUTPUT; }; foo \& ; sleep 5'` – yvs2014 Jun 30 '23 at 13:10
  • Maybe this can help: https://stackoverflow.com/a/7687722/18232031 – Arslan Sohail Bano Jun 30 '23 at 13:18
  • 2
    1. `tput` require a *tty*, `nohup` drop links to *tty* before running your command. - 2. What are you trying to do? Running in *background* a *function* that return a string, then end immediately?! – F. Hauri - Give Up GitHub Jun 30 '23 at 13:33
  • 1
    Perhaps an https://xyproblem.info/, what are you trying to achieve? – Diego Torres Milano Jun 30 '23 at 15:34
  • Not 100% sure what you mean by "I had no issues running it in the background, or with nohup description output, but not both." What is "nohup description output"? Are you saying that you can run it using `&`, you can run it using `nohup`, but you can't use both of them? What is inadequate about using one or the other? What is the behavior you are seeing that you do not expect? – Vercingatorix Jun 30 '23 at 18:52
  • So just to be clear, you want a script that you launch, which then returns to the terminal command line so you can issue more commands, but runs something in the background, and eventually breaks in and overwrites the screen (whatever you may be doing) with the output of "Do something"? – Vercingatorix Jun 30 '23 at 19:14

0 Answers0