Does bash support doing a read nested within a read loop?

前端 未结 1 409
清酒与你
清酒与你 2020-12-15 05:06

The bash read command is very convenient for:

  • read -p to prompt the user and capture input from the user
  • while read
相关标签:
1条回答
  • 2020-12-15 05:35

    The simplest fix is to have the outer read read from a different file descriptor instead of standard input. In Bash, the -u option make that a little easier.

    while read -u 3 item
    do
      # other stuff
      read -p "choose wisely: " choice
      # other stuff
    done 3< /tmp/item.list
    
    0 讨论(0)
提交回复
热议问题