[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: variables



On Mon, Feb 01, 2016 at 10:03:03PM +0100, Hans wrote:
> please apologize my maybe silly question, but I never understood, when 
> variables (and strings) are set in different marks and what it does mean.
> 
> I found "foo", `foo` and 'foo' at different tools. 
> 
> Maybe someone can enlighten me, when I should use which ones.

If you could suggest a specific tool, we could perhaps tell you the right
thing to use for that tool (or the reasons to use it).

In many scripting languages, single quotes means verbatim, and double quotes
means the string may be scanned and interpolated in some way. For example, in
bourne shell, 

	foo='this is $bar'

would set the variable foo to the value 'this is a $variable'. However, if
there existed a variable named bar with the value baz,

	foo="this is $bar"

would set value of foo to 'this is baz': the contents of the variable bar
would be interpolated into the string.

Backticks (``) are often used to cause the environment to execute an external
command, and then return the output of that command into the program. A shell
example

	currentdate=`date`

Ruby and Perl use backticks in a similar way.

-- 
Jonathan Dowland


Reply to: