Skip to content

Instantly share code, notes, and snippets.

@oxc
Last active August 29, 2015 14:19
Show Gist options
  • Save oxc/eb8edc3fd95fb1c971e0 to your computer and use it in GitHub Desktop.
Save oxc/eb8edc3fd95fb1c971e0 to your computer and use it in GitHub Desktop.
bash process substitution scoping
$ ./procsubtest.sh
Bash version: 4.3.33(1)-release
grep: /dev/fd/63: No such file or directory
grep: /dev/fd/63: No such file or directory
grep: /dev/fd/63: No such file or directory
grep: /dev/fd/63: No such file or directory
grep: /dev/fd/63: No such file or directory
$ ./procsubtest.sh
Bash version: 4.2.37(1)-release
/dev/fd/63:50857f1ad67ccb5eece006b4ea5b97f326574168 -
/dev/fd/62:b3a4c917040ac2eaf6cac8b5d271b150ff46505f -
/dev/fd/61:47a6bcafda11aea91c8aa3e22f6db529edd83cd9 -
/dev/fd/60:1d9e85d9814b49ccfd874fc5a8c2baae53d3e093 -
/dev/fd/59:b73a56f7d07c9acf98d6797899a80f10a20b8cbf -
#!/bin/bash
echo "Bash version: $BASH_VERSION"
function startPipes() {
# wrapped in a function so process substitution pipes stay open until the call
declare -a fargs
for i in 1 2 3 4 5; do
fargs+=(<(head -c 10 /dev/urandom | sha1sum))
done
grep -H . "${fargs[@]}"
}
startPipes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment