Linux 如何在shell脚本中打印$?
我希望输出为$msg1两三。$s和msg1之间没有空格。怎么可能呢Linux 如何在shell脚本中打印$?,linux,shell,terminal,Linux,Shell,Terminal,我希望输出为$msg1两三。$s和msg1之间没有空格。怎么可能呢 #!/bin/sh msg1=$ ms="$msg1 msg1" msg2="$ms two" msg3="$msg2 three" echo $msg3 只需引用$(或其周围的单词)。例如 如果您想要不带换行符的消息,请使用echo-n 请参见和您可以使用: msg1='$' ms="${msg1}msg1" msg2="$ms two" msg3="$msg2 three" echo "$msg3" 输出: $msg1
#!/bin/sh
msg1=$
ms="$msg1 msg1"
msg2="$ms two"
msg3="$msg2 three"
echo $msg3
只需引用
$
(或其周围的单词)。例如
如果您想要不带换行符的消息,请使用echo-n
请参见和您可以使用:
msg1='$'
ms="${msg1}msg1"
msg2="$ms two"
msg3="$msg2 three"
echo "$msg3"
输出:
$msg1 two three
$msg1 two three
注:注意${msg1}
语法,在msg1
周围创建变量边界。这是为了避免它使它变得非常简单:
输入:
echo '$msg1' two three
(注意单引号)
输出:
$msg1 two three