共計 335 個字符,預計需要花費 1 分鐘才能閱讀完成。
在 Linux 中,可以使用多種方法進行字符串拼接,其中比較常用的方法有使用 +
操作符、使用 $()
和使用 printf
命令。以下是這些方法的示例:
- 使用
+
操作符:
str1="Hello"
str2="World"
result=$str1$str2
echo $result
- 使用
$()
:
str1="Hello"
str2="World"
result=$(echo "$str1 $str2")
echo $result
- 使用
printf
命令:
str1="Hello"
str2="World"
result=$(printf "%s %s" "$str1" "$str2")
echo $result
以上是在 Linux 中進行字符串拼接的幾種常用方法,可以根據具體需求選擇合適的方法。
丸趣 TV 網 – 提供最優質的資源集合!
正文完