why I can’t pass my input in foo function

foo() {
	read -r -p "delete $name (default is no) [y/n]?  " choice
	choice="${choice:-n}"
	echo "\$choice: $choice"
}

printf "%s\n" "foo" "bar" "baz" "eggs" "spam" | while read -r name; do
	foo

Expected result:

delete foo (default is no) [y/n]? USER_INPUT
$choice: USER_INPUT
delete bar (default is no) [y/n]? USER_INPUT
$choice: USER_INPUT
# truncated

Actual output:

$choice: bar
$choice: eggs
$choice: n

[!NOTE] Actual output produced without user interaction

  • e55amOP
    link
    fedilink
    English
    arrow-up
    3
    ·
    4 days ago

    Sorry, I’ve dropped done by mistake when I pasted my snippet.

    And thanks for your explanation, but I didn’t fully understand how this happened.