Advertisement
devinteske

Dynamically filling file descriptors in sh(1)

Aug 11th, 2013
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.32 KB | None | 0 0
  1. #!/bin/sh
  2. fdset="3 4 5 6 7 8 9"
  3. data3="1"
  4. data4="2"
  5. data5="3"
  6. data6="4"
  7. data7="5"
  8. data8="6"
  9. data9="7"
  10. for n in $fdset; do
  11.     eval data=\"\$data$n\"
  12.     exec 9<<-EOF
  13.     $( echo "$data" )
  14.     EOF
  15.     [ $n -eq 9 ] || eval exec "$n<&9" "9<&-"
  16. done
  17. for n in $fdset; do
  18.     data=$( eval cat \<\&$n )
  19.     echo "data on fd($n): $data"
  20. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement