Back Ticks

Commands wrapped within BackTicks have their output turned into a scalar and returned. This allows programmers to capture the output of a command for later use. This construct is found in many UnixShells and in some programming languages such as PerlLanguage, PhpLanguage, and RubyLanguage.

Example: Putting the current year in a variable (for /bin/sh compatible shells)

 year=`date +%Y`
 echo $year
If the current year were 2004, this would output (surprise) "2004".


Also a good reason to practice PairTickInspection?. Back ticks are often difficult to identify and remove when inspecting alone.

Backticks can represent a serious security hazard if unvalidated text is executed (such as from a web page). Someone nasty could then get your CGI script to execute rm -r or worse.


In PythonLanguage, BackTicks are used as a quick and dirty way to inspect an object. Compare

 print thing
which calls thing's __str__ method (it prints the result of str(thing)), with

 print `thing`
which calls thing's __repr__ method (it prints the result of repr(thing)). (These are equivalent to comparing the outputs from an object's to_s and inspect methods in RubyLanguage, or the outputs from Ruby's puts and p.)

Note that backticks are deprecated and have been removed in Python 3. They should be replaced with a direct call to the repr() function instead.


I used to use BackTicks. When i started my most recent job, i was mocked for not writing

 $(expr)

instead. Now i am all about the $(). Dollar for the win. Comply.


In HaskellLanguage, you can use a regular function as an infix operator by surrounding the function name with BackTicks.

EditText of this page (last edited December 17, 2009) or FindPage with title or text search