I'm new to unix and I've already came across something that happens a lot.I type a command (for example, ps -eo 'tty,pid,comm') and get back text. As far as I understand, when I pipe the result into grep it should search the output and give me back results from that output. So why, then, do I get back a result that looks nothing like the command ps?I get back a long text that is not even in the form of the original ps command and consists of obscure information and looks like a setting file.
grep giving results that do not appear in the original context
grep;pipe;ps
It appears, based on your comment, that the output you're seeing is the contents of files that have a single character filename that match the name of the first of such files. The reason is that the ? character in your grep command is being expanded by the shell before being executed.Thus, your ps command is doing what it should, but grep is completely ignoring that input in preference to grepping files on the command-line.Demonstrate this for yourself by doing something like:mkdir ~/tempdircd ~/tempdirps -eo 'tty,pid,comm' | grep ?which will create an empty directory (no files in it), which will then allow the ? to fail to expand, and pass directly to grep. Then create two files like this:touch aecho thisisfilebwithana > band then re-run just the grep, like this:grep ?and you'll seethisisfilebwithanabecause grep saw this:grep a bwhich it interpreted as show me all the lines from file b that contain an 'a'.What you probably want to do instead, is escape the question mark:ps -eo 'tty,pid,comm' | grep \?orps -eo 'tty,pid,comm' | grep '?'