quotes

Bash nested quotes and eval

淺唱寂寞╮ 提交于 2019-11-30 17:48:07
I'm having difficulty nested quotes within a bash script argv="su -c '$RVM_PATH wrapper $config_rvm \'$PASSENGER_RVM_BIN $command $options\'' web" eval $argv The above got me eval: line 162: unexpected EOF while looking for matching `'' eval: line 163: syntax error: unexpected end of file argv="su -c \"$RVM_PATH wrapper $config_rvm \\\"$PASSENGER_RVM_BIN $command $options\\\"\" web" That's because \' doesn't have any special meaning within a single-quoted string; it means simply "backslash, followed by end-of-string". One option is to use $'...' instead of '... '; that will let you use

Why does $@ work different from most other variables in bash?

孤街醉人 提交于 2019-11-30 17:22:00
问题 The $@ variable seems to maintain quoting around its arguments so that, for example: $ function foo { for i in "$@"; do echo $i; done } $ foo herp "hello world" derp herp hello world derp I am also aware that bash arrays, work the same way: $ a=(herp "hello world" derp) $ for i in "${a[@]}"; do echo $i; done herp hello world derp What is actually going on with variables like this? Particularly when I add something to the quote like "duck ${a[@]} goose". If its not space separated what is it?

What's the accepted way of storing quoted data in XML?

微笑、不失礼 提交于 2019-11-30 17:16:21
What's the accepted way of storing quoted data in XML? For example, for a node, which is correct? (a) <name>Jesse "The Body" Ventura</name> (b) <name>Jesse \"The Body\" Ventura</name> (c) <name>Jesse "The Body" Ventura</name> (d) none of the above (please specify) If (a), what do you do for attributes? If (c), is it really appropriate to mix HTML & XML? Similarly, how do you handle single and curly quotes? Mitchel Sellers Your correct answer is A & C as the " is not a character that must be encoded in element data. You should always be XML encoding characters such as > , < , and & to ensure

python equivalent to perl's qw()

試著忘記壹切 提交于 2019-11-30 17:01:26
I do this a lot in Perl: printf "%8s %8s %8s\n", qw(date price ret); However, the best I can come up with in Python is print '%8s %8s %8s' % (tuple("date price ret".split())) I'm just wondering if there is a more elegant way of doing it? I'm fine if you tell me that's it and no improvement can be made. Well, there's definitely no way to do exactly what you can do in Perl, because Python will complain about undefined variable names and a syntax error (missing comma, perhaps). But I would write it like this (in Python 2.X): print '%8s %8s %8s' % ('date', 'price', 'ret') If you're really attached

Escape backquote in a double-quoted string in shell

不羁岁月 提交于 2019-11-30 16:52:47
For the command: /usr/bin/sh -c "ls 1`" (a backquote after 1). How to make it run successfully? Adding a backslash before "`" does not work. ` is a special char as we know, and I tried surrounding it with single quote too (/usr/bin/sh -c "ls 1'`'"), but that doesn't work either. The error always are: % /usr/bin/sh -c "ls 1\`" Unmatched ` You need to escape the backtick, but also escape the backslash: $ touch 1\` $ /bin/sh -c "ls 1\\\`" 1` The reason you have to escape it "twice" is because you're entering this command in an environment (such as a shell script) that interprets the double-quoted

What's the accepted way of storing quoted data in XML?

蹲街弑〆低调 提交于 2019-11-30 16:30:47
问题 What's the accepted way of storing quoted data in XML? For example, for a node, which is correct? (a) <name>Jesse "The Body" Ventura</name> (b) <name>Jesse \"The Body\" Ventura</name> (c) <name>Jesse "The Body" Ventura</name> (d) none of the above (please specify) If (a), what do you do for attributes? If (c), is it really appropriate to mix HTML & XML? Similarly, how do you handle single and curly quotes? 回答1: Your correct answer is A & C as the " is not a character that must be encoded in

ASP.NET single quotes are converted to '

大兔子大兔子 提交于 2019-11-30 12:12:57
Note: Most probably this will be a double question, but since I haven't found a clear answer, I'm asking it anyway. In ASP.NET I'd like to add some JavaScript to the onclick event of a CheckBox. I've simplified the case to this: <asp:CheckBox ID="TestCheckBox" runat="server" onclick="alert('test');" Text="Test" /> The resulting HTML is as follows: <input id="MainContainer_TestCheckBox" type="checkbox" name="ctl00$MainContainer$TestCheckBox" onclick="alert('test');" /><label for="MainContainer_TestCheckBox">Test</label> What particularly bothers me is that a single quote 'automatically' gets

How to display double quotes in JavaScript

六月ゝ 毕业季﹏ 提交于 2019-11-30 11:57:22
问题 On html page if I give name in double quotes then it is not getting reflected on page. It displays a blank string. I tried with escape() function but that didn't work. So what is the way to display a string in double quotes. One thing I forgot to mention that I want to display the string in input text box. 回答1: You have several options: var str = 'My "String"'; //use single quotes for your string var str = "My \"String\""; //escape your doublequotes var str = "My "String""; //use it as html

PowerShell: Quoting -replace & variables

被刻印的时光 ゝ 提交于 2019-11-30 11:34:50
This is in response to my previous question: PowerShell: -replace, regex and ($) dollar sign woes My question is: why do these 2 lines of code have different output: 'abc' -replace 'a(\w)', '$1' 'abc' -replace 'a(\w)', "$1" AND according to the 2 articles below, why doesn't the variable '$1' in single quotes get used as a literal string? Everything in single quotes should be treated as a literal text string, right? http://www.computerperformance.co.uk/powershell/powershell_quotes.htm http://blogs.msdn.com/b/powershell/archive/2006/07/15/variable-expansion-in-strings-and-herestrings.aspx When

Strange behavior of argv when passing string containing “!!!!”

本秂侑毒 提交于 2019-11-30 08:07:50
I have written a small program that takes some input parameters from *argv[] and prints them. In almost all use cases my code works perfectly fine. A problem only arises when I use more than one exclamation mark at the end of the string I want to pass as an argument ... This works: ./program -m "Hello, world!" This does NOT work: ./program -m "Hello, world!!!!" ^^ If I do this, the program output is either twice that string, or the command I entered previous to ./program. However, what I absolutely don't understand: The following, oddly enough, DOES work: ./program -m 'Hello, world!!!!' ^^ The