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
test.sh
#!/bin/sh
#Comment out
echo "Hello, World!"
Change permissions
$ chmod 755 test.sh
Execution result
$ ./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
sql.sh
#!/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.
test.txt
HELLO=hello
test.sh
#!/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
sql.cnf
USER=[User name]
PASS=[password]
It is not necessary to make it cnf separately, but it feels like entering from the shape
sql.sh
#!/bin/sh
. ./sql.cnf
mysql -u $USER -p$PASS
Execution result
$ ./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.
Recommended Posts