#] #] ********************* #] "$d_SysMaint"'Linux/read summary.txt' # www.BillHowell.ca 31May2018 initial # view in text editor, using constant-width font (eg courier), tabWidth = 3 Great blog examples at end of this file ... especially "...Reading from more than one file at a time..." #24************************24 29Jul2023 augment examples #] +-----+ #] force read from terminal, eg user input!!! or nested scripts fail!! #] read -p "Press [Enter] key to continue..." >"$pout681" # save paragraph cat "$ptmp681" | tr \\n ' ' | sed 's| \([0-9]*:[0-9]*\) | |g' >>"$pout681" rm "$ptmp681" bolInn=0 echo ' ' >>"$pout681" fi else echo "$line681" >>"$ptmp681" bolInn=1 fi done #] +-----+ #] withput pNum, exact lines, no trimming #] IFS='' to preserve leading [spaces,tabs] (IFS = "internal field separator") #] while IFS='' read -r line; do #] printf '%s\n' "$line" #] done < "$file" #] +-----+ #] file read loops - eval to expand variables!!, see "$d_bin""fileops.sh" #] pthOptrNamL_pthNdfL_argOrderNum() #] { #] pthOptrNamL="$1" #] pthNdfL="$2" #] while read -u 9 optrNam; do #] while read -u 8 pthNdf; do #] # echo "pthNdf= $pthNdf" #] evalStr="echo ""$pthNdf" #] pthNdfFull=$( eval "$evalStr" ) #] # echo "pthNdfFull= $pthNdfFull" #] pth_optrNam_getArgOrderNum_dout "$pthNdfFull" "$optrNam" #] done 8< "$pthNdfL" #] done 9< "$pthOptrNamL" #] } #] +-----+ #] repeat warning : #] force read from terminal, eg user input!!! or nested scripts fail!! #] read -p "Press [Enter] key to continue..." "$d_temp""d_remove_emails files.txt" #] while read -u 9 line; do #] cat "$d_withEml""$line" | sed 's/[A-Za-z0-9._-]*@[A-Za-z0-9._-]*//g' >"$d_noEmail""$line" #] done 9< "$d_temp""d_remove_emails files.txt" #] else echo "directory doesnt exist : $d_noEmail" #] fi #] else echo "directory doesnt exist : $d_withEml" #] fi #] } #] +-----+ #] read tab-separated-columns of text file : #] process_one_of_several() #] { #] paperNumSearch="$1" #] #] let "i = 1" #] #] #] while IFS=$'\t' read -r paperNumber copyright authorTitle; do #] if [ "$paperNumSearch" == "$paperNumber" ]; then #] colour="red" #] d_paperDone="$d_paperProb" #] process_file #] #] colour="white" #] d_paperDone="$d_list""all - copyrighted/" #] process_file #] #] let "i += 1" #] break #] fi #] done < "$p_paperSpec" #] #] rm "$p_pdftk_logs" #] } #] +-----+ #] to make the read in the loop body read from the terminal: #] exec 3<"somefile" #] while IFS= read -r words <&3; do #] read -r word1 word2 junk #] printf 'Got words = "%s"\n' "$words" #] printf 'Got word1 = "%s"\n' "$word1" #] printf 'Got word2 = "%s"\n' "$word2" #] done #] This makes the input to the first read come from the file somefile #] while the standard input stream of the second read will read from the terminal #] (or wherever the standard input stream of the script comes from). https://unix.stackexchange.com/questions/423160/problem-using-read-command-within-while-read-loop edited Feb 10 at 9:46 answered Feb 10 at 9:16 Kusalananda #] +-----+ #] repeat warning : #] force read from terminal, eg user input!!! or nested scripts fail!! #] read -p "Press [Enter] key to continue..."