Skip to content

Commit

Permalink
Alternative to using <& $fd
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Chu committed Aug 26, 2017
1 parent f39be99 commit afbfd5f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions spec/hard-coded-descriptors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit afbfd5f

Please sign in to comment.