Permalink
Browse files

Alternative to using <& $fd

  • Loading branch information...
Andy Chu
Andy Chu committed Aug 26, 2017
1 parent f39be99 commit afbfd5ffcae81b3300d7b8d1729fb16f5292c02f
Showing with 21 additions and 0 deletions.
  1. +21 −0 spec/hard-coded-descriptors.sh
@@ -28,6 +28,27 @@ interactive-stdin() {
done {fd}< $path
}
# Here stdin conflicts
interactive-stdin-bad() {
local path=$0 # This script
while read line; do
echo "[$line]"
read -p "Continue? " ans
[[ "$ans" != yes ]] && exit 1
done < $path
}
# Alternative way without explicit descriptors.
interactive-stdin-alternative() {
local path=$0 # This script
local tty=$(tty) # e.g. /dev/pts/23
while read line; do
echo "[$line]"
read -p "Continue? " ans < $tty
[[ "$ans" != yes ]] && exit 1
done < $path
}
# https://www.reddit.com/r/oilshell/comments/6tch5v/avoid_directly_manipulating_file_descriptors_in/
log-dates() {

0 comments on commit afbfd5f

Please sign in to comment.