In Linux if you type

sort < txtfile

is that the same thing as

cat txtfile | sort
link|improve this question

74% accept rate
feedback

1 Answer

up vote 6 down vote accepted

To your title question: No. Getting stdin from file contents (input redirection) is not the same as piping one program's output to another program's input.

But, as your cat actually just prints a file's contents, the result is effectively the same in that example.


But even just the following produce very different results:

$ cat * | sort
$ sort < *

If there's more than one matching file, the latter will produce

-bash: *: ambiguous redirect

since it's just not as flexible as the former, which will cat all matching files, and pipe them as input into sort.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.