03-12-2007, 02:25 PM
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=<
INSERT INTO 'items' ( 'title' , 'description' , 'type' , 'keywords' , 'location' , 'notes' , 'physlocation' )
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)
#!/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)