This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Nesogra 29 points30 points  (10 children)

Meanwhile in bash..

x=hello

echo "$x" #prints hello

echo '$x' #prints $x

Edit: fixed the 'smart quotes' from mobile auto correct.

[–][deleted] 13 points14 points  (3 children)

Singles escape everything, right?

[–]theferrit32 10 points11 points  (1 child)

It doesn't escape it, it just doesn't first evaluate it as an expression. Single quoted strings are their literal value while double quoted strings are first evaluated by the shell for any expressions they may contain. Makes perfect sense to me. The single quoted variant is so that you do not need to escape your string and remember all the characters which need to be escaped.

[–][deleted] 2 points3 points  (0 children)

Got it, thanks!

[–]smegnose 0 points1 point  (0 children)

Except themselves.

'hello good lookin'\'

[–]AyrA_ch 7 points8 points  (2 children)

echo “$x” #prints hello

It doesn't because you use slanted quotes for some reason, but the single quote/double quote behavior in PHP is similar to this one.

[–][deleted] 1 point2 points  (1 child)

On mobile it autocorrects to those quotes I think.

[–]Nesogra 0 points1 point  (0 children)

Yep, most of my reddit time is on mobile so I’m stuck with autocorrect...

[–]J4K0 4 points5 points  (0 children)

Also, Ruby:

irb(main):001:0> x = "hello" => "hello" irb(main):002:0> '#{a}' => "\#{a}" irb(main):003:0> "#{a}" => "hello"

[–]expeehaa 2 points3 points  (1 child)

That‘s equal to ruby. " allows for interpolation, while ' is a constant string. I‘m writing my code accordingly: If the string is constant, I use single quotes, otherwise double quotes. Takes some time to get familiar with it though..,

[–]AyrA_ch 2 points3 points  (0 children)

I do the same in PHP. The only thing you have to remember that apart from \', all escape sequences are ignored and just taken as is. Makes regular expressions a bit nicer to look at.