2

I'm using git bash on windows and was wondering how I can stop the terminal asking for more input following a pipe (typed by accident). I know it's unusual to type piped commands this way, but I'm trying to simulate certain actions a bash style terminal can do.
For example, my input looks like this:

zecuse MINGW64 ~/source/repos/Sim
$ echo test |
> echo here| (pipe typed by accident)
> (enter key was pressed)
> (the caret is sitting here waiting for another command)

The output for this chain of commands should only result in here being typed to the terminal since I didn't redirect the first echo. However, I don't know what should be typed after the accidental pipe to stop accepting input and run the commands.
I've tried ;, ctrl+c, and ctrl+d.

  • ; = bash: syntax error near unexpected token ';'
  • ctrl+c = killing the command so nothing happens. I thought this might happen.
  • ctrl+d = bash: syntax error: unexpected end of file

Is there a keyboard shortcut or an "empty" command that does nothing for this?

Update

The : suggestion from @Jesse_b's answer worked perfect and after looking up about I/O redirection I was able to get everything to appear in the terminal as I expected it. I'm making echo write to a string for some context about the project and am using git bash as a way to test what happens.

$ echo test >&0 |
> echo here >&2|
> :

produces

test
here

1 Answer 1

3

IMO the "correct" way is to press ctrl+c and redo your command, but as you have discovered that kills your output.

Additionally you could do several things:

: Which is essentially a "do nothing" command that will exit 0. This will end your pipeline but will not produce the output from your echo here command.
true Similar to the do nothing command, it will exit 0 effectively ending your pipeline
false Similar to : and true, this will exit your pipeline except it will exit with 1 instead of 0

The problem is the output of the previous command is sent "over the pipe" and into stdin to the next command. If the command you give does nothing with input you won't get the output.

Solution to your problem (but definitely should not be treated as a blanket solution to this problem in general) is to use cat.

$ echo test |
> echo here |
> cat
here

You must log in to answer this question.

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