Jay Taylor's notes

back to listing index

Prevent expressions enclosed in backticks from being evaluated in heredocs

[web search]
Original source (stackoverflow.com)
Tags: bash shell-scripting heredoc stackoverflow.com
Clipped on: 2016-05-05

I have a text like this:

foo bar
`which which`

If I do this using heredoc, I get a blank file:

  ~  echo <<EOT > out
heredoc> foo bar
heredoc> `which which`
heredoc> EOT
  ~  cat out

  ~  

How can I do this?

Edit

Oh sorry, I meant to do cat. Problem is that it writes this to the file: which: shell built-in command, ie, evaluations backticks. Any way to do this without evaluating?

With cat, I get

  ~  cat <<EOT > out
heredoc> foo bar
heredoc> `which which`
heredoc> EOT
  ~  cat out
foo bar
which: shell built-in command
  ~  

I don't want which which to be evaluated.

asked Oct 29 '12 at 12:58
Image (Asset 3/4) alt=
user1527166
1,0093916
up vote 12 down vote accepted

Quote the label to prevent the backticks from being evaluated.

$ cat << "EOT" > out
foo bar
`which which`
EOT

$ cat out
foo bar
`which which`
answered Oct 29 '12 at 13:02
Image (Asset 4/4) alt=
dogbane
126k39219308
   upvote
  flag
Oh sorry, I meant to do cat. Problem is that it writes this to the file: which: shell built-in command, ie, evaluations backticks. Any way to do this without evaluating? – user1527166 Oct 29 '12 at 13:04
   upvote
  flag
Quote the label to prevent the backticks from being evaluated. – dogbane Oct 29 '12 at 13:06
   upvote
  flag
Perfect, thank you :) – user1527166 Oct 29 '12 at 13:10
2 upvote
  flag
FYI this will also disable other bash expression (such as variable evaluation) from occurring. To just disable backtick evaluation you can escape the backticks by adding a backslash, e.g. '\`' – Keith Feb 6 '15 at 20:43

Your Answer

asked

3 years ago

viewed

899 times

active

3 years ago

Hot Network Questions

more hot questions
Technology Life / Arts Culture / Recreation Science Other
  1. Stack Overflow
  2. Server Fault
  3. Super User
  4. Web Applications
  5. Ask Ubuntu
  6. Webmasters
  7. Game Development
  8. TeX - LaTeX
  1. Programmers
  2. Unix & Linux
  3. Ask Different (Apple)
  4. WordPress Development
  5. Geographic Information Systems
  6. Electrical Engineering
  7. Android Enthusiasts
  8. Information Security
  1. Database Administrators
  2. Drupal Answers
  3. SharePoint
  4. User Experience
  5. Mathematica
  6. Salesforce
  7. ExpressionEngine® Answers
  8. more (13)
  1. Photography
  2. Science Fiction & Fantasy
  3. Graphic Design
  4. Movies & TV
  5. Seasoned Advice (cooking)
  6. Home Improvement
  7. Personal Finance & Money
  8. Academia
  9. more (9)
  1. English Language & Usage
  2. Skeptics
  3. Mi Yodeya (Judaism)
  4. Travel
  5. Christianity
  6. Arqade (gaming)
  7. Bicycles
  8. Role-playing Games
  9. more (21)
  1. Mathematics
  2. Cross Validated (stats)
  3. Theoretical Computer Science
  4. Physics
  5. MathOverflow
  6. Chemistry
  7. Biology
  8. more (5)
  1. Stack Apps
  2. Meta Stack Exchange
  3. Area 51
  4. Stack Overflow Careers
site design / logo © 2016 Stack Exchange Inc; user contributions licensed under cc by-sa 3.0 with attribution required
rev 2016.5.5.3546