LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Issue with cat (https://www.linuxquestions.org/questions/linux-newbie-8/issue-with-cat-4175633917/)

cuintilo 07-13-2018 05:35 AM

Issue with cat
 
Hello

I ran into this while training with command line.

When I use cat program without arguments, enter a line and press enter it copies said line to next paragraph like this:
Code:

$ cat
This is line0
This is line0

To my knowledge I haven't changed any variables permanently at least on purpose and couldn't find information how to revert this back to normal. I also tried to search logs, but couldn't find an answer.

There's been a lot new information for me to handle during last days so I'm not sure if I remember correctly, but this isn't how that buffer is supposed to work by default.

I'm using debian stretch at the moment. I don't necessarily need detailed answer, maybe a pointer to a correct log file etc. so I can solve issue myself. Thank you.

Turbocapitalist 07-13-2018 05:41 AM

It is working like it should and printing what it has received over to standard output (stdout). What are you trying to do with cat there?

With the way you are invoking it, you can exit with ctrl-d

Another way to invoke it would be with a Here Document which goes until it encouters a line starting with some designated text of your choosing:

Code:

cat << END-OF-TEXT
> foo
> bar
> END-OF-TEXT
foo
bar

But both those ways only print to stdout and won't capture the output to a file.

cuintilo 07-13-2018 05:48 AM

Quote:

Originally Posted by Turbocapitalist (Post 5878748)
It is working like it should and printing what it has received over to standard output (stdout). What are you trying to do with cat there?

With the way you are invoking it, you can exit with ctrl-d

Another way to invoke it would be with a Here Document which goes until it encouters a line starting with some designated text of your choosing:

Code:

cat << END-OF-TEXT
> foo
> bar
> END-OF-TEXT
foo
bar

But both those ways only print to stdout and won't capture the output to a file.

Actually now that I think about this more closely... It's a bit stupid. Basically I'm just trying to memorize basic commands/built-ins/programs etc. for now, so it's mostly playing around and tweaking stuff as I go. In this particular case I was just testing stuff while I ran into this.

My recollection of earlier times probably involved me putting output to some file. There it wouldn't do it the way it did now. But since there is no specified output it just echoes it immediately. Is this correct thinking?

Turbocapitalist 07-13-2018 05:57 AM

Quote:

Originally Posted by cuintilo (Post 5878749)
My recollection of earlier times probably involved me putting output to some file. There it wouldn't do it the way it did now. But since there is no specified output it just echoes it immediately. Is this correct thinking?

Yes, you can use redirection (and more redirection info) to capture what you are entering.

Code:

$ cat > /tmp/cat.log.txt                                               
foo
bar
^d
$ cat /tmp/cat.log.txt                                                 
foo
bar

Or

Code:

$ cat << END-OF-TEXT > /tmp/cat.log.txt                               
> foo
> bar
> END-OF-TEXT

$ cat /tmp/cat.log.txt                 
foo
bar

Understanding redirections is very useful. Memorizing programs isn't as much. You'll find yourself using the same ones often enough that you just start to remember them. For the rest, you'll known where and how to look up more information in the manual pages. Just-in-time rather than just-in-case knowledge inventory.

Code:

man cat
man man


cuintilo 07-13-2018 06:47 AM

Quote:

Originally Posted by Turbocapitalist (Post 5878752)
Understanding redirections is very useful. Memorizing programs isn't as much.

Thank you for link, currently I'm reading "The Linux Command Line" by William Shots. Already went over first stuff about redirection in it but one you linked is more detailed. I'm only trying to do memorization for these basic things, I know that in time it would come by itself but I want to speed up the process a bit. Not going to memorize every single program/command, just ones that appear the most. Should I mark this thread as "solved"? I don't know if my post was really an issue anyway, but at least I find that I got useful information. :)

Turbocapitalist 07-13-2018 07:22 AM

Quote:

Originally Posted by cuintilo (Post 5878761)
Thank you for link, currently I'm reading "The Linux Command Line" by William Shots. Already went over first stuff about redirection in it but one you linked is more detailed. I'm only trying to do memorization for these basic things, I know that in time it would come by itself but I want to speed up the process a bit. Not going to memorize every single program/command, just ones that appear the most. Should I mark this thread as "solved"? I don't know if my post was really an issue anyway, but at least I find that I got useful information. :)

No problem. TLCL is a very useful book, probably parts 1 and 4 are the most useful once you start to find your way around. It's been a while since I've last read it but I recall that I liked part 4 because if you do something once, you'll probably do it again, and if you have done it several times it is a good candidate for automation.

In general if you approach this like learning any other programming language, it might help. The programs are like functions, more or less.

Other good bash resources would be Greg Wooldge's Guide, FAQ, and Pitfalls, as well as his programming guide:

https://mywiki.wooledge.org/BashGuide
https://mywiki.wooledge.org/BashFAQ
https://mywiki.wooledge.org/BashPitfalls
https://mywiki.wooledge.org/BashProgramming

Speaking of bash, a lot of GNU/Linux users refer to the shell and bash interchangeably but bash is just one shell of several good ones. zsh is another good and advanced shell. In that way it might be useful to try both bash and zsh so you can compare and contrast two advanced shells. POSIX shells like dash are nicer for scripting since they are both more portable and much faster.

cuintilo 07-13-2018 07:44 AM

Quote:

Originally Posted by Turbocapitalist (Post 5878769)
In general if you approach this like learning any other programming language, it might help. The programs are like functions, more or less.

I'm trying to use this approach. I'm still relatively new into more serious world of computers. I completed introductory cs-course on edX which was done using Python and I learned many basic concepts there. Haven't really managed to complete anything worthwhile yet, but I feel that after I switched my OS to Debian (used windows 7 before) I have much better flow to learning. Might be just that theres so much information coming in that even my brain can't ignore all of it - when I was trying to learn stuff on windows it pretty much started and ended with me opening and closing IDE, or at least that's how I felt.

I wish I could get into some sort of project to gather more experience but haven't had courage yet to try getting through for example at github. Would be glad to try and spot bugs or anything that would contribute to something... Giving me some new skills in the process of course. :D


All times are GMT -5. The time now is 01:38 AM.