Looping through lines in a file in bash, without using stdin

后端 未结 3 791
无人及你
无人及你 2021-01-05 06:01

I am foxed by the following situation.

I have a file list.txt that I want to run through line by line, in a loop, in bash. A typical line in list.txt has spaces in.

3条回答
  •  滥情空心
    2021-01-05 06:50

    As an alternative, you can read from stderr, which by default is connected to the tty as well. The following then also includes a test for that assumption:

    (
    tty -s <& 2|| exit 1
    while read -r line; do
        echo "$line"
        echo 'Hit enter'
        read x <& 2
    done < file
    )
    

提交回复
热议问题