![]() |
BASH Scripting Help Needed: Scripting MySQL - Printable Version +- MacResource (https://forums.macresource.com) +-- Forum: My Category (https://forums.macresource.com/forumdisplay.php?fid=1) +--- Forum: Tips and Deals (https://forums.macresource.com/forumdisplay.php?fid=3) +--- Thread: BASH Scripting Help Needed: Scripting MySQL (/showthread.php?tid=29569) |
BASH Scripting Help Needed: Scripting MySQL - microchip13 - 03-12-2007 I'm here once again to consult the great knowledge present. I'm working on writing a web app thingy, and would like to input stuff into a database, it has to be by hand and I'd like to be able to do it easily and quickly. Currently my code is: #!/bin/bash #Ask if you are in enter mode. -e By the way if [ "$1" == -e ] ; then echo "Hello, welcome to Life." echo -------------------------- echo "You have chosen to enter information into the database." echo "-------------------------" echo -n "Please enter the title of the information --> " read $title echo "Please enter the description: " read $description echo -n "Please enter the type --> " read $type echo "Please enter the location" read $location echo "Please enter any notes" read $notes echo "Please enter the physical location if it applies" read $physlocation echo "Please enter any keywords you would like associated with this item." read $keywords /Applications/MAMP/Library/bin/mysql --user=microchip -p Life --execute=< VALUES ( '$title', '$description', '$type', '$keywords', '$location', '$notes', '$physlocation' );" EOF else echo "That's not valid" fi What I get is: ./Life.sh: line 1: items: command not found ./Life.sh: line 1: title: command not found ./Life.sh: line 1: description: command not found ./Life.sh: line 1: keywords: command not found ./Life.sh: line 1: location: command not found ./Life.sh: line 1: notes: command not found ./Life.sh: line 1: physlocation: command not found /Applications/MAMP/Library/bin/mysql: ambiguous option '--p' (pager, protocol) Meaning it's trying to execute the stuff in the backtics. I've tried putting \ infront of all the backticks but there's no luck there. Advice? TiA! Re: BASH Scripting Help Needed: Scripting MySQL - mattkime - 03-12-2007 i'm sure you have good reason - but what is wrong with a web interface? Re: BASH Scripting Help Needed: Scripting MySQL - microchip13 - 03-12-2007 Ultimately it will have a web interface, but for mostly searching and light duty entering. I'm creating this so have a database of everything, all of my files, physical objects and so fourth with then the web interface to search through it all. I'd prefer to have a rather streamlined way of entering information for physical objects right now opposed to a web interface. Re: BASH Scripting Help Needed: Scripting MySQL - mattkime - 03-12-2007 I know its not what you're looking for but I'd consider this - http://www.phpmyadmin.net/home_page/index.php Re: BASH Scripting Help Needed: Scripting MySQL - TheTominator - 03-12-2007 [quote microchip13]Meaning it's trying to execute the stuff in the backtics. I've tried putting \ infront of all the backticks but there's no luck there. Advice? Use regulartics instead of backtics in that SQL statement (i.e. single quotes). You use the normal ones in the VALUES part. I don't understand why you chose to use backtics in the INSERT INTO part. Re: BASH Scripting Help Needed: Scripting MySQL - TheCaber - 03-12-2007 Try this version: #!/bin/bash #Ask if you are in enter mode. -e By the way if [ "$1" = -e ] ; then echo "Hello, welcome to Life." echo -------------------------- echo "You have chosen to enter information into the database." echo "-------------------------" echo -n "Please enter the title of the information --> " read title echo "Please enter the description: " read description echo -n "Please enter the type --> " read type echo "Please enter the location" read location echo "Please enter any notes" read notes echo "Please enter the physical location if it applies" read physlocation echo "Please enter any keywords you would like associated with this item." read keywords /Applications/MAMP/Library/bin/mysql --user=microchip -p Life --execute=< VALUES ( "$title", "$description", "$type", "$keywords", "$location", "$notes", "$physlocation" ); EOF else echo "That's not valid" fi # end of chipscript The following changes were made: 1. The 'read' command takes the NAME of a variable as its argument, into which the line of standard input is placed. Putting a '$' in front of the name tells the shell to substitute the VALUE of the variable at the time of evaluation. 2. Use single quotes rather than backticks. backticks are 'execute this command and replace it with the standard output' . See "Command Substitution" in the bash man page. 3. Use double quotes around variables to get their values, not single quotes. I don't know what the issue with MySQL is about the --p or -p argument: /Applications/MAMP/Library/bin/mysql: ambiguous option '--p' (pager, protocol) |