Search code examples
bashcommand-line-interfacengrok

How do I prevent a bash script from exiting?


I am trying to augment ngrok http 80 by sending myself the random public address:

ngrok "$@" &

sendurl()

fg

Unfortunately, albeit ngrok screen comes back online, I get a prompt at the end of my bash script, like it terminated.

How do I keep ngrok running in the terminal "tab" as if I started it myself?


Solution

  • This is a bit of a hack but you can use a subshell and a minor sleep delay to get the desired functionality.

    (sleep 5 && sendurl(geturl())) & # Customise delay to whatever feels best
    
    ngrok "$@"