Skip to main content
Tweeted twitter.com/#!/StackUnix/status/122025248089587712
added 24 characters in body; edited tags
Source Link
Stéphane Gimenez
  • 29.5k
  • 3
  • 79
  • 88

How does commands like 'ls'ls know what its stdout is.?

It seems 'ls'ls is operating different depending on what the target stdout is, for. For example if iI do:

ls /home/matt/tmp 

ls /home/matt/tmpthe result is:

a.txt b.txt c.txt

howeverHowever if do I ls /home/matt/tmp | cat do

ls /home/matt/tmp | cat

the result is (i.e. new line per result):

a.txt
b.txt
c.txt

The process is passed a file descriptor 1 for stdout right? How does it determine how to format the result? Does the file descriptor reveal information?

How does commands like 'ls' know what its stdout is.

It seems 'ls' is operating different depending on what the target stdout is, for example if i do:

ls /home/matt/tmp

a.txt b.txt c.txt

however if do I ls /home/matt/tmp | cat

the result is (i.e. new line per result):

a.txt
b.txt
c.txt

The process is passed a file descriptor 1 for stdout right? How does it determine how to format the result? Does the file descriptor reveal information?

How does commands like ls know what its stdout is?

It seems ls is operating different depending on what the target stdout is. For example if I do:

ls /home/matt/tmp 

the result is:

a.txt b.txt c.txt

However if I do

ls /home/matt/tmp | cat

the result is (i.e. new line per result):

a.txt
b.txt
c.txt

The process is passed a file descriptor 1 for stdout right? How does it determine how to format the result? Does the file descriptor reveal information?

Source Link
user935712063
  • 559
  • 1
  • 3
  • 11

ls command operating differently depending on recipient

How does commands like 'ls' know what its stdout is.

It seems 'ls' is operating different depending on what the target stdout is, for example if i do:

ls /home/matt/tmp

a.txt b.txt c.txt

however if do I ls /home/matt/tmp | cat

the result is (i.e. new line per result):

a.txt
b.txt
c.txt

The process is passed a file descriptor 1 for stdout right? How does it determine how to format the result? Does the file descriptor reveal information?