how to use echo command to print out content of a text file?
51,205
Solution 1
echo
doesn't read stdin so in this case, the redirect is just meaningless.
echo "Hello" | echo
To print out a file just use the command below
echo "$(<a.txt )"
Solution 2
In Unix, I believe all you have to do, assuming you have a file that isn't hefty is:
cat <filename>
No echo
required.
Comments
-
Bernard about 3 years
I am trying to figure out what is the usage of this command:
echo < a.txt
According to text book it should redirect a programs standards input. Now I am redirecting a.txt to echo but instead of printing the content of the file it is printing out one empty line! Appreciate if anyone display this behaviour.
-
M.Ionut about 2 yearsHere for future reference: in my case,
echo "$(<a.txt )"
works with a bash shell (bash
), but not with a Bourne shell (sh
) - meaning that if you want thisecho "$(<a.txt )"
to work, you might need to have the first line of your script as#!/bin/bash
instead of#!/bin/sh
. Otherwise, it might not work.