5

This question already has an answer here:

I'm following "The Linux Command Line" by William Shotts. From what I understood, the > operator saves standard output to file, and < take standard input from file.

If the keyboard is the default standard input and < only takes that input from some file, why is ls -l not equivalent to ls < some_params.txt where some_params.txt would contain -l?

Thanks in advance

marked as duplicate by muru, Fabby, Jeff Schaller Jul 26 at 18:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

13

why is ls -l not equivalent to ls < some_params.txt where some_params.txt would contain -l?

Because the command line isn't the standard input!

ls is not a very good example here, since it doesn't use standard input. It just processes the command line options it gets, looks through some directories, and prints a listing to standard output.

But consider something like cat -n. It takes the -n flag from the command line, then reads from its standard input, adds line numbers and prints to standard output. Without < filename, the input comes from the terminal (i.e. your keyboard). With it, it comes from a file.

What you could do is use command substitution to insert the contents of a file to the command line. ls $(cat some_params.txt) (or ls $(< some_params.txt) in shells that support it) would do what you propose.

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