2

While working in bash (usually with git), what often happens to me is that I start some command and while that command is executing (which could take a while), I want to start composing the next command to execute right away, without waiting for the previous command to finish. If I finish composing the next command while the previous command is still executing, the next command should wait for the previous to finish before it actually starts.

Inadequate options that I found so far are:

  1. Just start writing the next command.

    The problem with this is that I'm writing blind: I can type the next command, but I don't see what I'm typing. This is especially problematic when it comes to tab-completion, because it behaves "unpredictably" (e.g. it's hard for me to guess if cd sTab will expand to cd src or not).

  2. Execute the previous command on the background using &.

    This means that the output of the previous command interleaves with the command I'm writing. The end result is that if the previous command outputs often enough, it's almost as bad as option #1.

  3. Hide the output of the previous command using > /dev/null

    The problem with this is that the output of the previous command is often important, especially in the case of failure.

To restate, is there some way to get an environment where:

  • I can write the next command while the previous command executes
  • I can see the command I'm writing
  • tab-completion works normally
  • output of the previous command is visible
4
  • 3
    Use a multiplexer like tmux or screen and work in an adjacent pane...
    – jasonwryan
    Commented Nov 6, 2016 at 20:56
  • You would have the previous command's output go to the screen, except when it's "too much". That seems unclear to me. Would it be acceptable to have the previous command output to a file?
    – Jeff Schaller
    Commented Nov 6, 2016 at 22:49
  • @JeffSchaller I guess writing to a pipe that's being shown by another window/pane would work.
    – svick
    Commented Nov 6, 2016 at 23:37
  • At that point I'd just simplify to Jason's idea above-- start command 1; if it's still running when you want to start a new command, open a new tab/session in screen or tmux and type the new command there.
    – Jeff Schaller
    Commented Nov 6, 2016 at 23:41

2 Answers 2

2

You have two choices:

  • The screen utility, though it doesn't ship with some Linux distros. It's not included by default in Solaris (Unix) either.

    For example, on Centos:

    yum install screen
    

    Here's a brief tutorial on screen utility usage.

  • The nohup command; redirect stdout and stderr accordingly:

    Example:

    nohup command & 
    
0
1

You can throw the currently-running command into the background with:

  • Ctrl-Z to suspend the process, and
  • bg to resume it in the background.

Then you have your prompt back and you can start typing the next command.

The previous command's stdout and stderr will still go to your terminal though.

You must log in to answer this question.

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