Part 1Say I have a command my_command that outputs multiple lines. I would like to capture the first line of my_command's output as soon as it's ready in a script, while keeping my_command running.I thought something like this would work:# Get a code that `my_command` prints in its first lineparsed_first_line=`my_command | grep -oEe '[0-9]+'` echo 'Here is the first line ' $parsed_first_linebut it doesn't. The echo statement is only reached only once my_command has fully finished, which is not what I want.Part 2Getting into more details: Imagine my_command is actually a command that connects my shell to a remote shell. Would this change in any way our solution to Part 1?In case the details matter, my_command is actually a one-line command: bsub /bin/zsh.This is a Platform LSF command that submits a job from a login machine (an interactive zsh shell in our case) to a remote grid. Once the submited job gets an open slot on the grid, LSF dispatches it, giving me an interactive shell on the remote machine.The first thing bsub does is output the job ID of my job on the remote queue (this is what I hope to parse in my script), and then once a slot is open, it dispatches my job.I'm wondering if a trivial solution to  Part 1 would work for Part 2 
Read first line of a command's output. Command connects me to a remote terminal
ssh;zsh
You use read to get one line of input at a time. You can do something like this:my_command | {   read line  line=$(grep -oEe '[0-9]+');  if [ $line ]; then    echo 'Here is the first line ' $line  fi  #possibly read more from my_command, transfer control to another program via `exec`, etc... }