Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
You can also use more and less, which display a file a page at a time, where page is whatever fits in the window. more only allows you to move forward in the file, less allows backwards scrolling too.
Yes echo can be used to display the contents of a file. The way I did it is by command substitution. The basic syntax is echo "`cat filename`". The contents of filename will be cat-ted and the standard output of cat will be substituted as a parameter for echo.
I have tried using redirections but it just doesn't work because echo does not receive its parameters from STDIN. Maybe someone else knows how to do it using redirections?
Or, if you need to print only particular parts of a file, you could use other tools such as awk (which may be a little overkill though). An example of awk printing a whole file is pretty useless (just one print statement), and more useful examples would be too plenty, so if you're interested you should search for howto or some awk manual. There are many available on the net, and the examples should give you a quick overview of what it is; just don't get fooled, awk can do a lot more than the examples (especially one-liners) can show. What I typically do with it is extract column data from files or do calculations where the data involved needs to be extracted from certain lines/columns in the file, leaving other content out.
Anyway, in principle awk does just as well as cat, even if it is quite a bit more complex.
When you can simply cat a file, why should we be using echo unless a specific purpose. I would always be simple.
Only the OP could possibly answer that question. IMHO my own reply comes closest to answering his question. I do agree with everyone here that cat, more, less, and awk are all much better ways to simply display the contents of a file.
Heh ... what is it with your obsession with 'echo'? =D
More than 60% of your posts are about echo ...
Cheers,
Tink
I was also wondering about that. Maybe he wants to start a new OS or something (echOS?).
Jokes apart, the only way I know is to use stdout as an argument for echo, as someone else pointed above, which is redundant and silly as also pointed above by someone else.
Code:
echo $(whatever)
You could invent lots of creative ways to do silly things with echo like
Code:
echo | xargs < myfile.txt
And so on, that doesn't solve the main point anyway: you should be using cat.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.