| 1 | #!/bin/sh
|
| 2 | #
|
| 3 | # Usage:
|
| 4 | # demo/fd-number.sh 8 # use FD 8
|
| 5 | # demo/fd-number.sh 100 # use FD 100
|
| 6 | # demo/fd-number.sh 1024 # use FD 1024
|
| 7 | # demo/fd-number.sh 1024 T # use FD 1024, but RAISE default ulimit to allow it
|
| 8 | #
|
| 9 | # Derived from Andriy's example:
|
| 10 | #
|
| 11 | # exec 25>out
|
| 12 | # echo hello>&25
|
| 13 | # cat out
|
| 14 | #
|
| 15 | # Except we generalize the FD number with 'eval'
|
| 16 |
|
| 17 | set -o errexit
|
| 18 |
|
| 19 | fd=${1:-8}
|
| 20 | set_ulimit=${2:-}
|
| 21 |
|
| 22 | # raise limit if necessary
|
| 23 | if test -n "$set_ulimit"; then
|
| 24 | ulimit -n "$(( fd + 2 ))" # +2 needed, not just +1 ?
|
| 25 | fi
|
| 26 |
|
| 27 | eval "exec $fd> _tmp/hello"
|
| 28 | echo "using fd $fd" >& $fd
|
| 29 |
|
| 30 | # with OSH, defeat 'builtin cat' optimization
|
| 31 | $(which cat) _tmp/hello
|