59

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 -)"
Community
  • 1
  • 1
ecbrodie
  • 10,326
  • 19
  • 64
  • 117
  • 4
    Per [this](http://fishshell.com/docs/2.0/faq.html#faq-subcommand) entry in the fish FAQ, sub-commands are denoted by surrounding them with parenthesis. e.g., `set foo (echo bar); echo $foo` outputs `bar`. – iscfrc Oct 06 '13 at 19:50

2 Answers2

79

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

BuZZ-dEE
  • 4,936
  • 10
  • 57
  • 84
Phlogisto
  • 916
  • 8
  • 6
11

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

echo "Found "(count $PATH)" paths in PATH env var"
  • So there is no way around temporarily closing the quote and reopening right after. https://fishshell.com/docs/current/tutorial.html#command-substitutions – aasutossh Jun 04 '21 at 15:46