LOK*_*ESH 2 linux shell terminal
我希望输出为$ msg1两三.$和msg1之间没有空格.怎么可能?
#!/bin/sh
msg1=$
ms="$msg1 msg1"
msg2="$ms two"
msg3="$msg2 three"
echo $msg3
Run Code Online (Sandbox Code Playgroud)
您可以使用:
msg1='$'
ms="${msg1}msg1"
msg2="$ms two"
msg3="$msg2 three"
echo "$msg3"
Run Code Online (Sandbox Code Playgroud)
OUTPUT:
$msg1 two three
Run Code Online (Sandbox Code Playgroud)
PS:记下${msg1}创建变量边界的语法msg1.这用于避免它成功$msg1msg1
只需引用$(或它周围的词)。例如
echo '$'
echo 'some$inside'
Run Code Online (Sandbox Code Playgroud)
如果您想要没有换行符的消息,请使用 echo -n
| 归档时间: |
|
| 查看次数: |
47334 次 |
| 最近记录: |