我正在使用以下命令由用户输入并希望将其显示为3num15
.
num --> 应该是用户输入的值。你能帮我语法吗?
echo "Enter the instance number of source system"
read num
Run Code Online (Sandbox Code Playgroud)
要在没有尾随空格的好处时打印或分配变量,您可以将其${}
用于参数扩展而不是$
...
echo "12${three}45"
Run Code Online (Sandbox Code Playgroud)
出于您的目的,这应该没问题,它可能是最常用的方法。另外,请注意,这echo "12$three"
将正常工作。尾随字符才是最重要的。它必须是在变量名中无效的字符。尽管如此,使用它并没有什么坏处echo "12${three}"
,我认为它提高了可读性。
有时你可能会看到类似这样的东西......
echo "12"$three"45"
Run Code Online (Sandbox Code Playgroud)
通常我会避免这种情况。或者有 printf ......
printf "12%d45\n" "$three"
Run Code Online (Sandbox Code Playgroud)
有关man printf
详细信息,请参阅,因为有很多可用的格式。