Printf pipe to ls in bash?

So, I learn about pipes in bash, and I found this detailed description:

The Unix channel connects the file descriptor STDOUT (standard output) the first process to STDIN (standard input) the second. What happens when the first process writes to STDOUT that the output can be immediately read (from STDIN) by the second process.

Source

Given this understanding, connect STDOUT printfto STDIN ls. For simplicity, type the parent directory ( printf ..).

~/Desktop/pipes$ mkdir sub
~/Desktop/pipes$ ls
sub
~/Desktop/pipes$ cd sub
(no files)
~/Desktop/pipes/sub$ printf .. | ls
(no files)
~/Desktop/pipes/sub$ 

I want to do: ls ..but it seems that all I get is that ls. Why is this so? How can I lsuse the parent directory pipes? Am I misunderstanding the pipes?

+4
2

stdin, ls. , stdout.

, . :

cat > file1
This is file1
^D

The ^ D <CTRL>+D, . , cat stdout file1. , stdin, " 1".

:

cat > file2
This is file2
^D

, :

cat < file1

:

This is file1

, :

cat file1 | cat file2

cat file2 < file1

? , cat stdin, , ls.

, :

cat - file1 < file2

- , stdin stdout .

+3

ls stdin, . , stdin, xargs, ls

printf "someSampleFolderOrFile" | xargs ls 

xargs man,

xargs -

+2

Source: https://habr.com/ru/post/1669781/


All Articles