Pergunta

Is there a better way to do command substitution in fish shell?

In bash I can do:

$ echo $(whoami) 
user

$ echo "I am: $(whoami)" 
I am: user

But in fish is looks like I have to do:

$ echo (whoami) 
user

$ echo "I am: (whoami)" 
I am: (whoami)

$ set who (whoami); echo "I am: $who" 
I am: user

Is that the recommended way to do command substitution in fish where the substitution needs to happen inside a quoted string?

Foi útil?

Solução

You could just pull the substitution out of the quotes

echo "I am:" (whoami)

To bring this answer up to date: fish 3.4 introduced $(...) command substitutions that are expanded within double quotes

echo "I am: $(whoami)"

Command substitution

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top