I am having errors where I am putting in code that should be working fine into a shell file and when I run it, it fails to run correctly. The error I am receiving from this is confusing me as well somewhat. Here is what I have:
echo "Please enter your student ID: "
read username
echo "Please enter your MySQL password: "
read -s password
db="db$username"
echo "DB username is $db"
$(mysql -D$db -u$username -p$password -se "CREATE TABLE...")
echo "That has been completed"
The SQL command has been truncated as this appears to have no relevance for the error.
If I run this code through putty I get this:
*******@csl-*******:~/tasks/SQL$ ./generate.sh
Please enter your student ID:
': not a valid identifierad: `username
Please enter your MySQL password:
': not a valid identifierad: `password
DB username is db
ERROR 1045 (28000): Access denied for user '-p'@'localhost' (using password: NO)
./generate.sh: line 7: $'\r': command not found
That has been completed
*******@csl-*******:~/tasks/SQL$
(The * represent hidden values)
I am not sure what the error is with this code here. I have tried under different circumstances such as using a Mac to create the file with exactly the same file on and run it through terminal and it works fine (off the same Linux server). However I also went back to the same Mac to try and re-run the code and got the same error as shown here - even though the code hasn't changed.
Some background information: Using Putty for SSH access, Filezilla for FTP, Sublime Text for code editor. Connecting to a remote Linux server to run from.