title: How to insert a complex linux terminal command's output to mysql database table
body: <p>I am trying to convert the following terminal command:</p>
  
  <pre><code>date +"%m/%d/%Y %H:%M:%S"
  </code></pre>
  
  <p>whose output is:</p>
  
  <p><code>12/07/2017 19:49:48</code></p>
  
  <p>into a terminal command that will INSERT the terminal output from the <code>date +"%m/%d/%Y %H:%M:%S"</code> as values in a mysql database table:</p>
  
  <p>The full terminal command I am trying to use is:</p>
  
  <pre><code>echo "INSERT INTO block (date, data, sha256) VALUES ($(date +"%m/%d/%Y %H:%M:%S"), "dogs are loyal", "6324542a2ce0b80ad32e45b5ca8e8b9dd02da8802c6fc9939637dabda113e35e");"| mysql blockchain -u root;
  </code></pre>
  
  <p>And I get the following error:</p>
  
  <pre><code>ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '19:49:48, dogs are loyal, 6324542a2ce0b80ad32e45b5ca8e8b9dd02da8802c6fc9939637da' at line 1
  </code></pre>
  
  <p>What is odd is I notice from the error that the "date" command runs but it is only capturing the <code>%H:%M:%S</code> since it mentions <code>19:49:48</code>.</p>
  
  <p>I tried running the command directly in the mysql command line interface and got the following error:</p>
  
  <p><code>ERROR 1305 (42000): FUNCTION blockchain.$ does not exist</code></p>
  
  <p>My database details are as follows:</p>
  
  <p>My database name is "blockchain", table is called "block", and table descriptions are listed below. </p>
  
  <pre><code>mysql&gt; show databases;
  +--------------------+
  | Database           |
  +--------------------+
  | information_schema |
  | blockchain         |
  | mysql              |
  | performance_schema |
  +--------------------+
  4 rows in set (0.01 sec)
  
  mysql&gt; show tables;
  +----------------------+
  | Tables_in_blockchain |
  +----------------------+
  | block                |
  +----------------------+
  
  mysql&gt; desc block;
  
  +--------+-------------------+------+-----+---------+----------------+
  | Field  | Type              | Null | Key | Default | Extra          |
  +--------+-------------------+------+-----+---------+----------------+
  | id     | int(255) unsigned | NO   | PRI | NULL    | auto_increment |
  | date   | varchar(20)       | NO   |     | NULL    |                |
  | data   | varchar(250)      | NO   |     | NULL    |                |
  | sha256 | varchar(64)       | NO   |     | NULL    |                |
  +--------+-------------------+------+-----+---------+----------------+
  </code></pre>
  
  <p>Based on these errors, I am assuming it has something to do with special character, primarily the "$", but it may also be the "+" or the " " blank space in the command.</p>
  
  <p>I did some research and I tried playing around with escape charactesr '' vs `` vs "$" vs "\" to have outputs of commands be INSERT values to mysql tables but
  I am still running into some issues and would like to reach out to this community as a last resort. </p>
  
  <p>Thank you for your patience and assistance in advance.</p>
  
  <p>Sincerely,</p>
  
  <p>A humbly committed student</p>