Nesting quotes in bash

Viewed 13293

I want to something like this in bash:

 alias foo='bar="$(echo hello world | grep \"hello world\")"; echo $bar;'; foo

Expected output: hello world

Ouput: grep: world": No such file or directory

  • The outer quotes have to be single quotes, with double quotes $bar would be empty.

  • The next quotes have to be double quotes, with single quotes $() wouldn't expand.

  • The inner quotes could be both type of quotes, but single quotes doesn't allow single quotes inside of them.

How to I achieve this?

4 Answers
Related