4

I decided to try fish shell, and I'm having trouble with some aliases. So I guess the painless way of doing the things would be executing the bash commands inside fish shell functions. Something like that :

function fish_function
start bash
    ... bash commands ... 
stop bash
end

Is that possible?

e.g: the command

pacman -Qtdq && sudo pacman -Rns $(pacman -Qtdq) 

doesn't work in fish shell and I have no idea how to convert this

2
  • I read that fish uses () for command subsitutions. Just try to remove the $.
    – kos
    Commented Mar 4, 2016 at 19:13
  • worked ! (after substituting '&&' for ';and')
    – tjbrn
    Commented Mar 4, 2016 at 19:31

1 Answer 1

4

Apparently fish uses ; and for && and () for command substitutions.

So just changing the command to

pacman -Qtdq; and sudo pacman -Rns (pacman -Qtdq)

should work.


Answering the actual question, normally you can get a statement to be executed in Bash simply by redirecting the statement to a bash command's STDIN by any mean (notice that I'm on Zsh, which supports here strings, and that the statement prints the content of a Bash-specific variable):

% <<<'echo $BASH' bash
/bin/bash

However as a general rule I'd suggest to use bash's -c option. For example here strings and pipes don't play too well with multiple commands, here documents will be expanded by the current shell, etc (nevertheless those need to be supported by the current shell).

Overall bash -c seems to be always a safe bet:

bash -c 'pacman -Qtdq && sudo pacman -Rns $(pacman -Qtdq)'

Which for multiple commands becomes something like this:

bash -c '
command1
command2
command3
'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .