Anonymous Anonymous - 1 year ago 107
Bash Question

Using echo command as stdin in shell?

I was trying to search for a way how to use echo with a program I have written in C.

The program takes a word from stdin as input and I would like to know the command that will put whatever I type into echo into my program's input.

I was shown how to do this once but I forgot to write the command down and now I forgot it and cannot find it anywhere.

Answer

To use echo, you can do:

echo foo | a.out

Depending on your PATH, you may need to add ./:

echo foo | ./a.out

(This is specifying a relative path to the program to be run, rather than letting the shell find it in PATH)

If you care about whitespace, you'll want to use quotes:

echo 'white    space matters' | ./a.out