Post History
That's my bash script. Actually, no, it isn't. Assuming for a second that the shebang line is #!/bin/sh (not #!bin/sh as you have it in the question), it's a sh shell script, not a bash shell ...
Answer
#2: Post edited
- > That's my bash script.
- Actually, no, it isn't. Assuming for a second that the shebang line is `#!/bin/sh` (not `#!bin/sh` as you have it in the question), it's a sh shell script, not a bash shell script. Assuming that your /bin/sh is actually bash (which it need not be; for example, Debian uses `dash` as `sh`), bash will start in a different mode when invoked as `sh`. Other shells may do things differently when invoked as `sh` or as some other name, or they might not.
- The distinction is unlikely to make any difference with such a simple shell script as you have in the question, but for more advanced features, it can make a very real difference.
- **That said**, ignoring the fact that this is through a shell script, it seems that your question actually is **"how do I invoke the `mysql` client such that it does not prompt interactively for a MySQL user's password, but authenticates using a password?"**.
- The answer to that is in the `mysql(1)` man page.
- A bare `mysql -p` asks the MySQL client to enter password authentication mode.
- **The `-p` can also take a password,** either as `--password=qwerty` or `-pqwerty` (note the absence of a space separating `-p` and the password).
The man page also notes that passing a password on the command line is insecure ([this answer of mine](https://software.codidact.com/posts/277511#answer-277517 "Is it unsecure to use a password on the command line to run a MySQL script on Windows?") has a more in-depth discussion on why that is).- Note that when invoked in this manner, the shell executing the script will wait for the `mysql` process to exit before continuing with the `rails` command. That's probably not what you actually want. To execute a command in the background and continue with the execution of the script without waiting for that command to actually finish, you would use `&` to background the process, but since `mysql` is an interactive tool, that would make little sense here.
- > That's my bash script.
- Actually, no, it isn't. Assuming for a second that the shebang line is `#!/bin/sh` (not `#!bin/sh` as you have it in the question), it's a sh shell script, not a bash shell script. Assuming that your /bin/sh is actually bash (which it need not be; for example, Debian uses `dash` as `sh`), bash will start in a different mode when invoked as `sh`. Other shells may do things differently when invoked as `sh` or as some other name, or they might not.
- The distinction is unlikely to make any difference with such a simple shell script as you have in the question, but for more advanced features, it can make a very real difference.
- **That said**, ignoring the fact that this is through a shell script, it seems that your question actually is **"how do I invoke the `mysql` client such that it does not prompt interactively for a MySQL user's password, but authenticates using a password?"**.
- The answer to that is in the `mysql(1)` man page.
- A bare `mysql -p` asks the MySQL client to enter password authentication mode.
- **The `-p` can also take a password,** either as `--password=qwerty` or `-pqwerty` (note the absence of a space separating `-p` and the password).
- The man page also notes that passing a password on the command line is insecure ([this answer of mine](https://software.codidact.com/posts/277511/277517#answer-277517 "Is it unsecure to use a password on the command line to run a MySQL script on Windows?") has a more in-depth discussion on why that is).
- Note that when invoked in this manner, the shell executing the script will wait for the `mysql` process to exit before continuing with the `rails` command. That's probably not what you actually want. To execute a command in the background and continue with the execution of the script without waiting for that command to actually finish, you would use `&` to background the process, but since `mysql` is an interactive tool, that would make little sense here.
#1: Initial revision
> That's my bash script. Actually, no, it isn't. Assuming for a second that the shebang line is `#!/bin/sh` (not `#!bin/sh` as you have it in the question), it's a sh shell script, not a bash shell script. Assuming that your /bin/sh is actually bash (which it need not be; for example, Debian uses `dash` as `sh`), bash will start in a different mode when invoked as `sh`. Other shells may do things differently when invoked as `sh` or as some other name, or they might not. The distinction is unlikely to make any difference with such a simple shell script as you have in the question, but for more advanced features, it can make a very real difference. **That said**, ignoring the fact that this is through a shell script, it seems that your question actually is **"how do I invoke the `mysql` client such that it does not prompt interactively for a MySQL user's password, but authenticates using a password?"**. The answer to that is in the `mysql(1)` man page. A bare `mysql -p` asks the MySQL client to enter password authentication mode. **The `-p` can also take a password,** either as `--password=qwerty` or `-pqwerty` (note the absence of a space separating `-p` and the password). The man page also notes that passing a password on the command line is insecure ([this answer of mine](https://software.codidact.com/posts/277511#answer-277517 "Is it unsecure to use a password on the command line to run a MySQL script on Windows?") has a more in-depth discussion on why that is). Note that when invoked in this manner, the shell executing the script will wait for the `mysql` process to exit before continuing with the `rails` command. That's probably not what you actually want. To execute a command in the background and continue with the execution of the script without waiting for that command to actually finish, you would use `&` to background the process, but since `mysql` is an interactive tool, that would make little sense here.