*NIX enthusiast, Metal Head, MUDder, ex-WoW head, and Anon radio fan.

  • 0 Posts
  • 3 Comments
Joined 2 years ago
cake
Cake day: June 12th, 2023

help-circle

  • Wild, I get syntax error: unexpected end of file when I run your code, so just that alone is very confusing.

    When you’re inside foo here, STDIN is the pipe. Once I fix this syntax error that you somehow dodge and add some extra debugging, you can get a better picture of what’s going on here:

    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
            printf "Got name '%s'\n" "$name"
            echo calling foo
            foo
    done
    
    Got name 'foo'
    calling foo
    $choice: bar
    Got name 'baz'
    calling foo
    $choice: eggs
    Got name 'spam'
    calling foo
    $choice: n