Search code examples
linuxbashwhile-loopnano

Pause in a bash while loop


I am currently given the task to check the content of multiple files manually. I have all the files listed in a text file, line for line (newline at the end of each line), and currently trying to work out a bash script that Is capable of reading the textfile – line for line and then open them in nano for inspection. Problem occurs when I open it in nano – I am currently running linux on win10 as a subsystem, so I only have the terminal available. My current problem is when I try to do this:

Cat file | while read line; do nano “$line”; done

Minimal working example:

mkdir test
cd test
touch {a,v,c}
ls > file
Cat file |  while read line; do nano “$line”; done

are all file processed at the same time, or it tries to – it loops over all the files and ends – without allowing me to check the file in nano or allow me to properly close it.

Is possible to somehow pause the while loop while I have the file open In nano ?


Solution

  • Cat file |  while read line; do nano “$line”; done
    

    Nano might be trying to interact with you through its standard input, which is the pipeline. Try redirecting its standard input from your TTY:

    Cat file |  while read line; do nano “$line” < /dev/tty; done