Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a case where I am passing a content of a file to a command like this:

cat file_name.txt | my_command

But I want to pass a string directly, without reading a txt file content. So I want to have something like this:

"my file content as a string" | my_command

But of course I am getting an error "Command not found."

Please help me to come up with this. Thanks!

share|improve this question
up vote 8 down vote accepted

Just do

echo "my file content as a string" | my_command
share|improve this answer
yeees, sure :)!!! – Narek Sep 14 '09 at 12:22
No, no, no my question was very simple but I have casually missed that “echo” will work fine!, please roll back to your prev answer. – Narek Sep 14 '09 at 12:26
This is a wrong answer. echo "foo" will actually pass "foo\n". It has to be echo -n "foo". – Anonymous Sep 14 '09 at 13:34
That depends on what your my_command is expecting – wzzrd Sep 14 '09 at 13:35

Echo is fine, with bash you can also use a here string if you want. For example:

grep tak <<<"foo bar tak"


foo="bar tak"
grep tak <<<$foo
share|improve this answer

echo "my file content as a string" | my_command

share|improve this answer

You can simply type :

my_command "my file content as a string"
share|improve this answer
Whether that would work, depends heavily on the command used – wzzrd Sep 14 '09 at 12:24
in my case that is not a solution, sorry – Narek Sep 14 '09 at 12:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.