#!/bin/bash
VAR019='priusr'
VAR901='pripasswd'
echo 开发者_开发百科"CREATE DATABASE ftp;
GRANT SELECT, INSERT, UPDATE, DELETE ON ftp.* TO '${VAR019}'@'localhost' IDENTIFIED BY '${VAR901}';
This will output
: command not found
: command not found
: command not found
: command not found
How can I fix this? What am I doing wrong?
I suggest using a here document to reduce complexity of quoting.
#!/bin/bash
VAR019='priusr'
VAR901='pripasswd'
cat <<HERE
CREATE DATABASE ftp;
GRANT SELECT, INSERT, UPDATE, DELETE ON ftp.* TO '${VAR019}'@'localhost' IDENTIFIED BY '${VAR901}';
HERE
To the skeptics, here is the output:
CREATE DATABASE ftp;
GRANT SELECT, INSERT, UPDATE, DELETE ON ftp.* TO 'priusr'@'localhost' IDENTIFIED BY 'pripasswd';
Make sure your file is using right EOL (newline separating).
I had exactly the same problem some time ago and it was caused by newlines being \r\n
(Windows-style) instead of \n
(Linux style).
In that case, Linux assumes that \r
is a name of command and tries invoking it. But \r
is "invisible" character, that's why the strange-looking error message.
See this link on how to convert CRLF to LF.
I just cut and pasted what you put in your program. The only issue I had was the lack of a closing double-quote quotation mark.
I got the following output:
CREATE DATABASE ftp;
GRANT SELECT, INSERT, UPDATE, DELETE ON ftp.* TO 'priusr'@'localhost' IDENTIFIED BY 'pripasswd';
Which seems to be what you want.
The :command not found
is strange. For example, here's what I get when I enter nonsense:
$ asdas
bash: asdas: command not found.
This looks like maybe BASH isn't executing your script, or you think it's executing your script, but it's really executing another script. Use the which
command and make sure that your version of the script is being executed.
You can also use the bash
command itself: bash myscript.sh
. This way, you're verifying that your script is being executed with the BASH shell, and that it is your script that's being executed and not some other script in your path.
Another possibility is that /bin/bash
is not where your bash
executable is actually located. You might want to verify that too. I know I've seen this when running Perl scripts with #! /usr/bin/perl
on top, and Perl was actually located in /bin/perl
or /usr/local/bin/perl
.
Also make sure your shebang is formatted correctly. For example, there is no whitespace before the #
, and it's the first character on the line. That the !
is right next to the pound sign. Some processors or shells require one and only one space between the shebang and the name of the command interpretor.
精彩评论