```bash
a={b,c}d
echo $a
```
```
{b,c}d
```

In Bash how to make the output be `bc cd` instead?
Jun 7, 4:16pm

In Bash, the expression {b,c}d is a brace expansion, which expands to bd cd by default. To get the output bc cd, you need to ensure the comma is treated as a literal character and not as a separator for brace expansion.

Solution

Escape the comma with a backslash (\) to prevent brace expansion:

bash
a={b\,c}d
echo $a

Output:

text
{b,c}d

But if you want the output to be bc cd, you need to remove the braces and just use the comma as a literal separator:

bash
a=b,c
echo ${a//,/ }

Output:

text
b c

Or, if you want to keep the d at the end:

bash
a=b,cd
echo ${a//,/ }

Output:

text
b cd

For your exact case (bc cd):

If you want the output to be bc cd from {b,c}d, you need to remove the braces and the d and replace the comma with a space:

bash
a=b,c
echo ${a//,/ }

Output:

text
b c

If you want bc cd, you need to adjust the input:

bash
a=bc,cd
echo ${a//,/ }

Output:

text
bc cd
Jun 7, 4:16pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.

Vibe can make mistakes. Check answers. Learn more