Cannot understand command substitution in Fish shell

后端 未结 2 1174
温柔的废话
温柔的废话 2021-01-05 08:11

In sh:

~$ `echo ls`
bin/  Desktop/

But in fish:

fish: Illegal command name “(echo ls)”
~% (echo ls)

(Note

2条回答
  •  时光取名叫无心
    2021-01-05 08:49

    It has to do with the order of expansions.

    From help expand-command-substitution in fish:

    When combining multiple parameter expansions, expansions are performed in the following order:

     * Command substitutions
     * Variable expansions
     * Bracket expansion
     * Pid expansion
     * Wildcard expansion
    

    Expansions are performed from right to left, nested bracket expansions are performed from the inside and out.

    From man bash:

    The order of expansions is: brace expansion, tilde expansion, parameter, variable and arithmetic expansion and command substitution (done in a left-to-right fashion), word splitting, and pathname expansion.

提交回复
热议问题