Fish shell - How to interpolate a subcommand?

Joshua Cheek picture Joshua Cheek · Jun 15, 2014 · Viewed 7.5k times · Source

In bash I can say:

$ echo "a$(echo b)c"
abc

How do I do this in the fish shell?

Answer

ridiculous_fish picture ridiculous_fish · Jun 15, 2014
echo a(echo b)c

If you have quotes, you must exit them:

echo "a"(echo b)"c"

If your subcommand may have newlines, as of fish 2.3, you have to save and restore $IFS:

set -l IFS 
echo "a"(cat ~/file.txt)"c"
set -e IFS

Eventually string will be able to handle this case.