0

I only want echo $(date) to return the date not the backticked version.

echo $(date) # should return Wed Mar 6 09:50:41 EST 2019
echo `date` # should return `date` 
  • 2
    Backticks are part of the grammar, it would be strange if you could disable them. Use single quotes around the string you want to print instead, that would stop the backticks from being special in the shell. I'm not turning this into an answer as I don't know all the ins and outs of the zsh shell. – Kusalananda Mar 6 at 15:03
  • I did not know about single quotes. that's good enough for me. It was mostly about when I do git commits and want to add markdown inline. – Josh Beauregard Mar 6 at 15:20
  • @JoshBeauregard if you type git commit without -m, you actually get a text editor (vi on older systems, nano on newer), and then you don't have to worry about magic characters – Ferrybig Mar 6 at 15:42
  • I have vi set as my editor bit sometimes I just want to make a small commit faster. – Josh Beauregard Mar 6 at 15:43
2

Wrap the backticks in string quotes to divest them of their subshelly powers:

$ echo '`echo`'
`echo`

Beware, though, the contraction wrapped in strong quotes:

$ echo 'I can't process this.'
> Oh whoops that ">" means we're still in a strong quote.
I cant process this.
Oh whoops that ">" means were still in a strong quote.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.