Skip to content

Instantly share code, notes, and snippets.

@marek-saji
Last active December 26, 2015 05:29
Show Gist options
  • Save marek-saji/7101008 to your computer and use it in GitHub Desktop.
Save marek-saji/7101008 to your computer and use it in GitHub Desktop.
stdin in scripts
#!/bin/sh
F=/dev/stdin
while : ; do
ls -al "$F" 2>/dev/null
F=$( readlink "$F" )
[ -z "$F" ] && break
done
$ 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
$ 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
$ 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