![]() ![]() You can pass no filename arguments, and it will read from its own standard input. (You're not trying to pass multiple patterns to grep, but if you were, you could use the -e option, whose operand is always treated as a pattern.) The first non-option argument to grep is the pattern, but subsequent non-option arguments are treated as filenames from which input will be taken. You can pass it filenames as command-line arguments, and it will read from those files. Like cat and many other commands, grep accepts input in two ways: You piped ls output to grep, but grep did not read from the pipe.Ī pipe connects the standard output of one command to the standard input of the other. If you were to add more such files to the directory, then grep f* would pass more than those two filenames as arguments to grep, but file0.txt and file1.txt would still be included among them. Since those are the only two files in the current directory whose names start with f, the command-line arguments passed to grep from running grep f* are exactly the same as those passed to it from running grep file0.txt file1.txt. ![]() ( This kind of shell expansion is known variously as globbing, filename expansion, and pathname expansion.)īased on your description, there are exactly two files that match the f* glob: file0.txt and file1.txt. Each such name was passed to grep as a separate argument. Because f* was not quoted, the shell expanded it into the names of files in the current directory that start with f. Globs are treated specially by your shell. grep f* did not pass an argument of f* to grep. Your grep program is not broken, and the behavior you have observed is the correct and expected behavior, which is why reinstalling grep and rebooting did not change it. When grep reads from named files, its default behavior of reading from standard input doesn't apply, so it doesn't read data piped to it from another command. When you run grep f* in a situation where your shell expands f* to two or more arguments, grep considers all but one of them as names of files to open and read. Grep did not use the output of ls in any way. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |