Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
and after reading the mysql.run file there is no ' symbol. I did try to replace symbol with code \048' but this is not working for me. Propebly I'm doing something wrong but dont know what.
it is example, but it is not working if I am using the double quote. After "cd test" the script stops. If I remove double quotes after echo -n and use one quote then the script is working but it removes the quotes for '192.168.0.1', '30003', '30003', 'callofduty2' .And this quote needs to be there.
AIUI, the mechanism is that the shell you are issuing the command from parses the line and creates a single word of everything between the " characters. Parsing removes the outer " characters and substitutes the $dquote variable so it now looks like
Code:
cd test; echo -n "USE lgsl; INSERT INTO lgsl (ip, q_port, c_port, type) VALUES ('192.168.0.1', '30003', '30003', 'callofduty2');" > mysql.run; cd test2
This is passed to another shell (on a remote system?) that parses it again. Parsing removes the outer " characters so it now looks like
Code:
cd test; echo -n USE lgsl; INSERT INTO lgsl (ip, q_port, c_port, type) VALUES ('192.168.0.1', '30003', '30003', 'callofduty2'); > mysql.run; cd test2
What we can't see in the code above is that the string from USE to ); is a single word, the argument for the echo -n command.
If this works and it's OK to have a space before USE lgsl in file mysql.run, you can simplify it by changing
The quoting options for bash are quite simple, but double-quotes behave differently from single-quotes.
Put simply, double-quotes expands variables and allows you to escape special characters (like dollar signs and quotes) using a backslash, while single-quotes do not.
Single quotes just produce a literal string, and aren't very useful when you want to nest quotes, because you can't escape things. There is an alternative to escaping: if you leave no space between any two parameters, then they are run together as one (quoted or not). This is just an example, but you could use something like this to produce a single quote in parentheses (where the parentheses are single-quoted):
Code:
echo '('"'"')'
Note that a single quote is treated as a regular character when inside a double quotes, and so doesn't need escaping.
Your example uses BASH to launch another bash shell, and passes a single string to it that is then treated as a command, so you have to escape your quotes (by wrapping them in other quotes) in order to prevent them from being treated as ending quotes. This is called nesting strings.
To take your example, you could nest it using escaped double-quotes like this:
Thx for replay, unfortunatlly this is not working. I will c/p the command that I'm using. The problem is that I can't put double quotes inside first double quotes, if there is only one double quote symbol inside " " the script will stop. So there is no way that i can use double quotes in my command.
If I put variable dquote='"' the script will stop to work in that place.
The /' is not working, I get some error message when i try to echo with /'
Maybe to replace the ' symbol with something else that echo command will output to file and after the echo creates the mysql.run file using the sed command to change to ' symbol. This will probably work but Iam looking for more simpler solution.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.