-
-
Save marek-saji/7101008 to your computer and use it in GitHub Desktop.
stdin in scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
F=/dev/stdin | |
while : ; do | |
ls -al "$F" 2>/dev/null | |
F=$( readlink "$F" ) | |
[ -z "$F" ] && break | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sh ~/-.sh | |
lrwxrwxrwx 1 root root 15 Oct 18 12:18 /dev/stdin -> /proc/self/fd/0 | |
lrwx------ 1 saji saji 64 Oct 22 15:44 /proc/self/fd/0 -> /dev/pts/35 | |
crw--w---- 1 saji tty 136, 35 Oct 22 15:44 /dev/pts/35 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sh ~/-.sh < ~/foo | |
lrwxrwxrwx 1 root root 15 Oct 18 12:18 /dev/stdin -> /proc/self/fd/0 | |
lr-x------ 1 saji saji 64 Oct 22 15:44 /proc/self/fd/0 -> /home/saji/foo | |
-rw-r----- 1 saji saji 6 Oct 22 15:18 /home/saji/foo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat ~/foo | sh ~/-.sh | |
lrwxrwxrwx 1 root root 15 Oct 18 12:18 /dev/stdin -> /proc/self/fd/0 | |
lr-x------ 1 saji saji 64 Oct 22 15:44 /proc/self/fd/0 -> pipe:[4470786] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment