title: Bash - Adding a item to a textfile
body: <p>I have a formatted textfile that contains the store item's details in such a format.</p>
  
  <pre><code>item:username:quantity:price 
  </code></pre>
  
  <p>So it'll be like </p>
  
  <pre><code>Nike - Rucksack:testingabc:01:25.00 
  </code></pre>
  
  <p>To allow the store owner to keep track of his items in the store.</p>
  
  <p>I've tried the following code, but I would like to check if the item exists before entering it.</p>
  
  <pre><code>function addnewitem
  {
  echo -n "Item: " ; read ITEM
  echo -n "Username: " ; read USERNAME
  
  result="$(grep -q "$ITEM" ItemStored.txt)"
  echo "$result"
  
  if [ $result -eq "1"  ] ; then  
     echo "Error! Item already exists!"    
  else 
  echo -n "Quantity: " ; read QUANTITY
  echo -n "PRICE : " ; read PRICE
  echo "$ITEM:$USERNAME:$QUANTITY:$PRICE" &gt;&gt; ItemStored.txt ;
  echo "New item '$ITEM' has been added successfully!"
  fi
  </code></pre>
  
  <p>While entering, I get such an error though.  [: -eq: unary operator expected</p>