Here, I would like to introduce the basic operation of shell script.
It also serves as a memorandum, so I would like to increase it little by little.
First from the basics
It seems that the first line is Shebang, which specifies the script. Hmm
#!/bin/sh #Comment out echo "Hello, World!"
$ chmod 755 test.sh
$ ./test.sh Hello, World!
Here, we are trying to enjoy the troublesome things when starting the application. Most things that can be done with a shell can be done
Example: MySQL Run normally for the time being
$ mysql -u [user name] -p Enter password: mysql>
It is troublesome to enter the user name and password each time ...
First and simplest
#!/bin/sh mysql -u [User name] -p[password] #-Do not open a space next to p
You can run it with this, but with this you have to change that part sql.sh every time you change your username and password ... (I don't think it's too much trouble because it's only one line ...) So I'll just read it into another file.
#!/bin/sh . ./test.txt echo $HELLO
Run Don't forget to change your permissions! !!
$ ./test.sh hello
You can see that it is being read from another file.
Let's actually load it separately and execute it
USER=[User name] PASS=[password]
It is not necessary to make it cnf separately, but it feels like entering from the shape
#!/bin/sh . ./sql.cnf mysql -u $USER -p$PASS
$ ./sql.sh mysql>
How was it? That's where I can think of it. Also, if I find or come up with an efficient method, I would like to write it.