I need to put variable inside a double quotes inside single quotes.
I want to create common expression language like below.
passbolt list resource --filter 'FolderParentID == "**some-imaginary-id**"'
Just help replace some-imaginary with some bash variable. Thanks in advance.
You need to concatenate separate strings via juxtaposition (i.e., putting them directly next to each other, with no intervening whitespace).
passbolt list resource --filter 'FolderParentID == "'"$some_variable"'"'
Note there are three separate quoted strings:
FolderParentID == "
, in single quotes$some_variable
, in double quotes"
, in single quotesRegardless of the type of quotes used to quote each of the three, the results are concatenated into a single word.
At the expense of a command substitution, might want to use printf
to generate the string for you.
passbolt list resource --filter "$(printf 'FolderParentID == "%s"' "$some_variable")"
Here you can "nest" the double quotes, because the command substitution starts a new quoting context: the first "
inside the command substitution does not close the initial "
that contains the command substitution.