DEV Community

Daniella Mesquita
Daniella Mesquita

Posted on

Bash: quotes inside quotes without printing'em

contents="$(jq ".name = \"$writefrom_caproj_name\"" "$manifestwebapp_absolute_path")" && \
# credits from https://linuxconfig.org/string-concatenation-in-bash
echo "${contents}" > manifest.webapp
Enter fullscreen mode Exit fullscreen mode

Special attention to this part:

"$(jq ".name = \"$writefrom_caproj_name\"" "$manifestwebapp_absolute_path")"
Enter fullscreen mode Exit fullscreen mode

It simply doesn't works, as "$manifestwebapp_absolute_path" is using quotes inside quotes.

And using \"$manifestwebapp_absolute_path\" results in escaping the quotes BUT is also printing them.
So, how to use quotes inside quotes, somewhat like escaping them but without printing'em out?
Many thanks in advance! 🙏

Note: with proper answers turning into a solution, this question will be later turned into an explanation post.

Top comments (1)

Collapse
 
fyrfli profile image
Camille

Something is ringing a bell and I am wondering if this might solve your problem:

Have you tried using single quotes to wrap what you want contents to be set to?