Questions tagged [backticks]

For questions relating to the backtick character (`), also known as the backquote, which has various special meanings in computing.

A backtick or backquote or grave accent is the character,

       `

On British and American QWERTY keyboards, this is located in the upper left corner, next to the 1 key. It is notoriously difficult to type on some European keyboards, requiring up to four keystrokes.

Backticks were introduced by Unix shells to run a sub-shell. The concept has been adopted by other languages and tools such Perl, PHP, Ruby, and Make. The newer alternative syntax $(<command>) in POSIX-compliant shells is more flexible as it allows nesting.

In Python 2, backticks enclose an expression to be evaluated and converted to its string representation. This feature was removed in Python 3, as it was deemed not sufficiently beneficial to warrant the syntax. The same effect can be accomplished with repr() instead.

In Markdown, backticks are used as a shorthand for emitting <code></code> tags in HTML.

In TeX typesetting, a backtick renders as an opening curly quote (‘).

In the programming languages D and Go, backticks surround string literals.

Further uses of backticks in computing can be found in the Wikipedia article on the grave accent.

311 questions
10
votes
4 answers

How to capture both STDOUT and STDERR in two different variables using Backticks in Perl

Let's say I want to run an external program from my script with backticks and at the same time I want to capture both STDOUT and STDERR but in two different variables. How can I do that? For istance if I run this script... my $cmd = `snmpwalk -v…
raz3r
  • 3,071
  • 8
  • 44
  • 66
10
votes
4 answers

How do I grep for a backtick?

So I'm trying to find backticks (`) in files, so I ran: grep -irl '\`' ./* This seems to return every single file possible... What else can I try?
bafromca
  • 1,926
  • 4
  • 27
  • 42
10
votes
1 answer

GNU m4: escaping backticks (`)

A simple GNU m4 question, but I cannot find the correct answer. I'd like to print a markdown header starting/ending a code section: ``` echo Hello ``` How do I create a GNU M4 macro containing the 3 backticks ? something…
Pierre
  • 34,472
  • 31
  • 113
  • 192
9
votes
3 answers

Common Lisp Backquote/Backtick: How to Use?

I am having trouble with Lisp's backquote read macro. Whenever I try to write a macro that seems to require the use of embedded backquotes (e.g., ``(w ,x ,,y) from Paul Graham's ANSI Common Lisp, page 399), I cannot figure out how to write my code…
sadakatsu
  • 1,255
  • 18
  • 36
9
votes
4 answers

Text highlighting for ES6 template literals (backticks) in IntelliJ IDEA

Where should I look in the settings to remove the green background highlighting for text within the backticks? I think it is related to HTML in non-HTML files, probably it has nothing to do with quotes or backticks. I've been searching through…
9
votes
7 answers

perl backticks: use bash instead of sh

I noticed that when I use backticks in perl the commands are executed using sh, not bash, giving me some problems. How can I change that behavior so perl will use bash? PS. The command that I'm trying to run is: paste filename <(cut -d \" \" -f 2…
David B
  • 29,258
  • 50
  • 133
  • 186
9
votes
1 answer

What are the rules of string manipulation when using backticks (grave accents)?

In PHP when you write a set a variable equal to a string wrapped in grave accents, it gets executed as it would if it were inside a shell_exec() command. What does the grave accent symbol (`) ( not single quote) represent in PHP? So, in php you can…
Kristian
  • 21,204
  • 19
  • 101
  • 176
9
votes
9 answers

How do I get the output of curl into a variable in Perl if I invoke it using backtics?

I'm trying to get the response of a curl call into a variable in perl. my $foo = `curl yadd yadda`; print $foo; does not work. When I run this at the command line the curl call prints all its output correctly in the terminal, but the variable is…
Yevgeny Simkin
  • 27,946
  • 39
  • 137
  • 236
8
votes
1 answer

Why do I get a syntax error in backticks, even though it works in terminal?

I am trying to run a Linux command in Perl using backticks. It works when I run it directly in Linux, but when Perl does it through backticks, I get this error: sh: -c: line 0: syntax error near unexpected token `>' sh: -c: line 0:…
user3307598
  • 515
  • 1
  • 5
  • 13
8
votes
4 answers

angular2, file should end with a newline, and trailing space

I am new to angular2 and typescript, I got this 3 errors, I don't understand how to fix trailing whitespace and file should end with a newline.
user1034127
  • 349
  • 3
  • 5
  • 14
8
votes
2 answers

Is it possible to set an environment variable to the output of a command in cmd.exe

I need to do the equivalent of set ENVAR=`some-command` In a windows/cmd.exe script. Cygwin is not an option. For bonus marks: Is there some cmd.exe equivalent of backticks in general?
Peter Graham
  • 11,323
  • 7
  • 40
  • 42
8
votes
1 answer

How can I use Groovy to execute a shell command that has backticks?

I’m unable to use Groovy to execute a shell command that has backticks. A simplified example: println "echo `date`".execute().text I searched around and tried to figure out how to escape them somehow, but without luck.
Dag
  • 10,079
  • 8
  • 51
  • 74
7
votes
2 answers

How to flush output in backticks In Perl?

If I have this perl app: print `someshellscript.sh`; that prints bunch of stuff and takes a long time to complete, how can I print that output in the middle of execution of the shell script? Looks like Perl will only print the someshellscript.sh…
Ville M
  • 2,009
  • 7
  • 30
  • 45
7
votes
2 answers

How to execute Windows CLI commands in Ruby?

I have a file located in the directory "C:\Documents and Settings\test.exe" but when I write the command `C:\Documents and Settings\test.exe in single qoutes(which I am not able to display in this box), used for executing the commands in Ruby, I am…
Apoorv Saxena
  • 4,086
  • 10
  • 30
  • 46
7
votes
1 answer

Capturing "command not found" errors from Ruby's backticks?

Is there a way to capture a "command not found" error in a Ruby script? For instance, given: output = `foo` How do I trap the situation where foo isn't installed? I expected that I could rescue an exception, but this doesn't seem to work on 1.8.7.…
kfb
  • 6,252
  • 6
  • 40
  • 51
1 2
3
20 21