• 0 Posts
  • 3 Comments
Joined 2 months ago
cake
Cake day: August 3rd, 2025

help-circle


  • Remus86@lemmy.ziptoBash@lemmy.mlread user input problem
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    2 months ago

    Do this instead to treat name as a locally scoped variable:

    foo() {
        local name="$1"
        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 "$name"
    done