Repeat this text in a file named notes.txt and run the script
Before bash is a good language a blank line appears
Also, the following notes are displayed incorrectly
What is bad?
==================================
Title : Note 1
==================================
Category: Computer
Date : 2019-04-28 17:34:19
==================================
BASH is good language
==================================
1
2
'
while : ; do
read line1
read tit
read line2
read cat
read dat
read line3
note=""
while [ "$not" != "==================================" ]; do
read not
note="$note
$not"
done
read nro1
read nro2
#=============================================
# note.tmp
#=============================================
echo "$line1" >note.tmp
echo "$tit" >>note.tmp
echo "$line2" >>note.tmp
echo "$cat" >>note.tmp
echo "$dat" >>note.tmp
echo "$line3" >>note.tmp
echo "$note" >>note.tmp
echo "$nro1" >>note.tmp
echo "$nro2" >>note.tmp
clear
cat note.tmp
read -p "Press enter to continue" jj </dev/tty
done <notes.txt
'
note="$note$not\n"
...
echo -ne "$note" >>note.tmp
--- Post updated at 07:32 ---
For what's here infinite "while" ?
--- Post updated at 07:48 ---
read -p "Press enter to continue" jj </dev/tty
there is option -u
read -p "Press enter to continue" -u 1 jj
while :: do
...
done < notes.txt
Totally pointless loop
Then it's better
jj=""
while [ "$jj" != q ]; do
{
...
} < notes.txt
read -p "Press enter to continue" jj
echo "Start over"
sleep 2
done
infinite while is because the notes can have 1, 2 or more lines, until find the fourth line with equal signs.
Thank you
The following appends even the first line as a new line, so the initial empty string becomes an empty line:
note=""
while [ "$not" != "==================================" ]; do
read not
note="$note
$not"
done
You must either branch on a state variable (e.g. $firstrun), or use the "$separator variable" trick as follows:
note="" sep=""
while
read not &&
[ "$not" != "==================================" ]
do
note="$note$sep$not"
sep="
"
done
EDIT: I have changed the oder of read
and [ ]
. Otherwise one must initialize not=""
(or it might have the value from a previous cycle).