Bash user prompt when reading a file

I am trying to create a user prompt when reading a file line by line in Bash. The idea is that I can split the various files one by one using Gnuplot. Here is what I have:

#!/bin/bash echo "Enter filename that contains the filenames:" read fname xr="[1e8:1e20]" yr="[1:1e13]" while read line do echo -e "reset\nset log\nset xrange$xr\nset yrange$yr\nset xlabel \"Frequency [Hz]\"\nset ylabel \"F_{/Symbol n} [Jy Hz]\"\nset key top left\nplot \"$line.dat\" u 3:(\$3*\$4)*1e26 wl ti \"$line^o\" \n"> plt.gp gnuplot plt.gp done < $fname 

I would like to enter user input / "continue?" before the gnuplot plt.gp command, because at the moment it just quickly unwraps everything and then exits. The standard -p read command does not work here. I read somewhere that I might need to use the file descriptor descriptor descriptor 5 command, but I don't understand. Thanks.

+4
source share
1 answer
 #!/bin/bash read -p 'Enter filename that contains the filenames: ' fname xr="[1e8:1e20]" yr="[1:1e13]" while read line do echo -e "reset\nset log\nset xrange$xr\nset yrange$yr\nset xlabel \"Frequency [Hz]\"\nset ylabel \"F_{/Symbol n} [Jy Hz]\"\nset key top left\nplot \"$line.dat\" u 3:(\$3*\$4)*1e26 wl ti \"$line^o\" \n"> plt.gp gnuplot plt.gp read -p 'Do you want to continue? [Y/n]: ' want_to_continue </dev/tty case "${want_to_continue}" in Y|y) continue ;; *) echo "OK. Bye!" break ;; esac done < ${fname} 
+6
source

Source: https://habr.com/ru/post/1385210/


All Articles