0

I have 2 variable in a bash script that look like this:

key='fox'

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

I'd like to create a new variable where key is inserted between the words brown and jumps. How can I do this in bash? I was trying something like this, but I couldn't get it to work:

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

The variable of sentence should be:

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

1 Answer 1

5

You can write:

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

using double-quotes instead of single-quotes. (Parameter expansion, and all other substitutions, are disabled within single-quotes; see §3.1.2.2 "Single Quotes" in The Bash Reference Manual.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.