本文介绍了如何打印文字字符串"$ 1"在bash脚本中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要打印一个名为"$ 1"的字符串.但是,当我用echo执行此操作时,它会打印等于"$ 1"变量的字符串.如何像字符串一样打印"$ 1"?
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?
例如:
set -- "output" # this sets $1 to be "output"
echo $1 # ==> output
但是我想要这个:
echo $1 # ==> $1
推荐答案
您必须转义 $
才能显示它:
You have to escape the $
to have it shown:
$ echo "\$1"
或者,正如JeremyP在注释中指出的那样,只需使用单引号使 $ 1
的值不会扩展:
or, as noted by JeremyP in comments, just use single quotes so that the value of $1
does not get expanded:
$ echo '$1'
这篇关于如何打印文字字符串"$ 1"在bash脚本中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!