0

我在 bash 脚本中有 2 个变量,如下所示:

key='fox'

string='The quick brown jumps over the lazy dog'

我想创建一个新变量,key插入到单词brown和之间jumps。我怎样才能在 bash 中做到这一点?我正在尝试这样的事情,但我无法让它工作:

sentence='The quick brown ${key} jumps over the lazy dog'

句子的变量应该是:

string='The quick brown fox jumps over the lazy dog'
4

1 回答 1

5

你可以写:

sentence="The quick brown ${key} jumps over the lazy dog"

使用双引号而不是单引号。(参数扩展和所有其他替换在单引号内被禁用;请参阅The Bash Reference Manual中的第 3.1.2.2 节“单引号”。)

于 2013-05-29T20:16:57.123 回答