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?
The stuff inside
$()represents a subshell, so you are allowed to place un-escaped double quotes inside