Note that there are some explanatory texts on larger screens.

plurals
  1. PObash scripting variable allocation when using here-document
    text
    copied!<p>I am new to bash /mysql however I have found tons of help reading threw examples and other people's problems ...but have ran into one of my own . I am attempting to insert a row into an MySQL database table every time a file is added to a specific directory (for this i am using inotifywait ) anyways here is my bash script </p> <pre><code>#!/bin/bash while true; do filename= "false" filename= inotifywait --format "%f" -e create /var/www/media2net/torrent date_field= date +"%F":"%T" mysql --host=localhost --user=root --password=admin Media2net &lt;&lt; EOF insert into video (title, description, url_video, upload_date) values('testing','default_description','$filename', '$date_feild'); EOF echo $filename done </code></pre> <p>From this I have verified with echo the variable <code>$filename</code> is properly held at end of bash script however when i look at entry in the table the column url_video has it's default value and not the string represented by <code>$filename</code> </p> <p>From what i can conclude the variable <code>$filename</code> does not get passed through EOF i have tried as indicate here <a href="http://www.dba-oracle.com/t_access_mysql_with_bash_shell_script.htm" rel="nofollow noreferrer">http://www.dba-oracle.com/t_access_mysql_with_bash_shell_script.htm</a> </p> <p>as well as this </p> <p><a href="https://stackoverflow.com/questions/3900496/using-shell-script-to-insert-data-into-remote-mysql-database">Using shell script to insert data into remote MYSQL database</a></p> <p>any help of where i can find how to pass variable into query would be greatly appreciated</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload