Have you ever wondered why "ls" shows you columns but works perfectly with other unix utils, as though every filename is placed on its own line?
$ ls
file_a file_f file_k file_p file_u file_z
file_b file_g file_l file_q file_v
file_c file_h file_m file_r file_w
file_d file_i file_n file_s file_x
file_e file_j file_o file_t file_y
$ ls | wc
26 26 182
$ ls | grep w
file_w
There is a way to know whether output stream referring to tty or not.
ReplyDeleteman isatty
Command line utilities often use it to work fine in different environment.