Q:

Bash programming — how to add string into text file

touch log.txt
while [ 1 ]; do 
 echo "insert data: "
 read data
 if [ $data = "finish" ]; then
  break
 fi
 echo "$data" >> log.txt

When I run the program and type in a word in an input like "hello im martin", it gives me an error saying unexpected operator.  How to fix this? 

A:

You're missing a done keyword after your echo statement that signifies the end of the while loop. 
Additionally, you should put the $data on line 5 in quotes, otherwise the hello im martin input will cause that line to be interpreted as:
if [ hello im martin = "finish" ]; then

