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!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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
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
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):
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.