1

I know this has probably been asked in various ways on this forum, and around the web, but I have tried all methods to no avail. I have a while read loop with a "read -p" contained in an if statement within it. I understand that the standard input is the .txt file being pumped into the while loop, so read-p can't be piped to user input. What will be my recourse here. Please take a look at the code.

while read orasid1
do
if [ "$prompt1" = "yes" ]; then
read -p "Do you want to change the password for $username on $orasid (y/n)?" Yesno2

    case ${Yesno2:0:1} in
            y|Y )

    echo "Yes"
#Call SQL script here
    ;;
    * )
    "No"
    ;;
    esac

else

exit 16

fi

done < $log_dir/pwd_change_$server.txt

I'll appreciate whatever help anyone can give.

1
  • Don't use standard input for the outer loop. Use an alternate fd instead. Or open an fd to the tty and use that fd in the inner read. Commented Jun 12, 2015 at 19:24

1 Answer 1

2

Use a different file handle for the outer read:

while read -u 3 orasid1; do
    ...
done 3< "$log_dir/pwd_change_$server.txt"

This is useful for any command (not just read) inside the body of the loop which might read (necessarily or not) from standard input.

You are still free to redirect standard input for the script as a whole from another file, for instance if you want to store canned responses to the various prompts in a file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.