quotes

When to wrap quotes around a shell variable?

两盒软妹~` 提交于 2019-11-25 21:32:23
问题 Could someone tell me whether or not I should wrap quotes around variables in a shell script? For example, is the following correct: xdg-open $URL [ $? -eq 2 ] or xdg-open \"$URL\" [ \"$?\" -eq \"2\" ] And if so, why? 回答1: General rule: quote it if it can either be empty or contain spaces (or any whitespace really) or special characters (wildcards). Not quoting strings with spaces often leads to the shell breaking apart a single argument into many. $? doesn't need quotes since it's a numeric

How to escape a double quote inside double quotes?

人走茶凉 提交于 2019-11-25 20:31:06
Can anybody show me how to escape double quote inside a double string in bash? For example in my shell script #!/bin/bash dbload="load data local infile \"'gfpoint.csv'\" into table $dbtable FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY \"'\n'\" IGNORE 1 LINES" I can't get the ENCLOSED BY \" with double quote escape correctly. I can't use single quote for my variable because i want to use variable $dbtable . Use a backslash: echo "\"" # Prints one " character. kenorb Simple example of escaping quotes in shell: $ echo 'abc'\''abc' abc'abc $ echo "abc"\""abc" abc"abc It's done by

Regex for quoted string with escaping quotes

那年仲夏 提交于 2019-11-25 16:58:46
How do I get the substring " It's big \"problem " using a regular expression? s = ' function(){ return " It\'s big \"problem "; }'; PhiLho /"(?:[^"\\]|\\.)*"/ Works in The Regex Coach and PCRE Workbench. Example of test in JavaScript: var s = ' function(){ return " Is big \\"problem\\", \\no? "; }'; var m = s.match(/"(?:[^"\\]|\\.)*"/); if (m != null) alert(m); This one comes from nanorc.sample available in many linux distros. It is used for syntax highlighting of C style strings \"(\\.|[^\"])*\" As provided by ePharaoh, the answer is /"([^"\\]*(\\.[^"\\]*)*)"/ To have the above apply to