Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to print string called "$1". But when I do this with echo it prints string which equals to "$1" variable. How can I print "$1" just like string?

for example:

$1 = "output"

echo $1 ==> output

But I want this:

echo $1 ==> $1

share|improve this question

2 Answers 2

up vote 5 down vote accepted

You have to escape the $ to have it shown:

$ echo "\$1"

or

$ echo '$1'

thanks JeremyP.

share|improve this answer
1  
or echo '$1' (use single quotes) –  JeremyP May 8 '13 at 16:11
    
Thanks, @fedorqui, again! :) –  Ziyaddin Sadigov May 8 '13 at 16:12
    
i will make it accepted answer very soon ;) –  Ziyaddin Sadigov May 8 '13 at 16:13
    
Thanks, @JeremyP! So here we are again Ziyaddin :D –  fedorqui May 8 '13 at 16:15
1  
Oh thanks @ZiyaddinSadigov, but you'll learn this and much more here in SO, it is what happened to me :D See you soon! –  fedorqui May 8 '13 at 16:31

You need to either:

  • Enclose the variable in SINGLE quotes: echo '$1'
  • Escape the $ sign: echo "\$1"
share|improve this answer
    
thanks, @carlos-campderros! –  Ziyaddin Sadigov May 8 '13 at 16:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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