如何在 Bash 中连接字符串变量 [英] How to concatenate string variables in Bash

查看:27
本文介绍了如何在 Bash 中连接字符串变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 PHP 中,字符串按如下方式连接在一起:

In PHP, strings are concatenated together as follows:

$foo = "Hello";
$foo .= " World";

这里,$foo 变成了Hello World".

Here, $foo becomes "Hello World".

这是如何在 Bash 中实现的?

How is this accomplished in Bash?

推荐答案

foo="Hello"
foo="${foo} World"
echo "${foo}"
> Hello World

通常要连接两个变量,您可以一个接一个地编写它们:

In general to concatenate two variables you can just write them one after another:

a='Hello'
b='World'
c="${a} ${b}"
echo "${c}"
> Hello World

这篇关于如何在 Bash 中连接字符串变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆