7

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

1 Answers1

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.

ilkkachu
  • 138,973