Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何在shell脚本中打印$?_Linux_Shell_Terminal - Fatal编程技术网

Linux 如何在shell脚本中打印$?

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

我希望输出为$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 two three
$msg1 two three
注:注意
${msg1}
语法,在
msg1
周围创建变量边界。这是为了避免它使它变得非常简单:

输入:

echo '$msg1' two three    
(注意单引号)

输出:

$msg1 two three