kjprice
kjprice

Reputation: 1318

Bash read and stderr redirection

So I've got a script that runs test cases on another script. I'm trying to redirect stderr while running the test cases. The part that is giving me problems is the read command:

within script1:

read -p "Delete $file? (y/n) " input

within testscript:

$script $opts $file 2>/dev/null

The read calls from script1 get redirected as well.

Upvotes: 5

Views: 1489

Answers (2)

dimba
dimba

Reputation: 27581

You can go simple:

echo "Delete $file? (y/n)"
read input

Upvotes: 1

John Kugelman
John Kugelman

Reputation: 361585

Redirect the prompt to stdout.

read -p "Delete $file? (y/n) " input 2>&1

Upvotes: 5

Related Questions