Fish equivalent of bash $(command) notation

ShellFishCommand Substitution

Shell Problem Overview


I am currently trying out the fish shell instead of using bash. One type of notation I'm having trouble learning the fish-equivalent notation for is $(command), similar to how it is described in this SOF post. How do I write this using fish? Keep in mind that I could use backslash characters around the command I want to evaluate, but the linked post and other posts discourage this because it is an old style of evaluating commands.

Specifically, this is the bash command I want to convert to fish syntax (for initializing rbenv during startup of the shell):

eval "$(rbenv init -)"

Shell Solutions


Solution 1 - Shell

In fish, $ is used only for variables. Correct notation equivalent to bash $(command) is just (command) in fish.

Solution 2 - Shell

FYI: If you additionally need to use this inside a string:

echo "Found "(count $PATH)" paths in PATH env var"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionecbrodieView Question on Stackoverflow
Solution 1 - ShellPhlogistoView Answer on Stackoverflow
Solution 2 - ShellJairo Andres Velasco RomeroView Answer on Stackoverflow