1

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!

Narek
  • 245
  • 1
  • 4
  • 15

4 Answers4

8

Just do

echo "my file content as a string" | my_command
wzzrd
  • 10,409
  • 2
  • 35
  • 47
4

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

grep tak <<<"foo bar tak"

Or:

foo="bar tak"
grep tak <<<$foo
Kyle Brandt
  • 83,619
  • 74
  • 305
  • 448
1

echo "my file content as a string" | my_command

Mark
  • 754
  • 1
  • 7
  • 12
0

You can simply type :

my_command "my file content as a string"
Denis R.
  • 293
  • 1
  • 2
  • 6