The fish shell and executing programs from bash through `function`

Athan Clark picture Athan Clark · Jan 8, 2015 · Viewed 7.6k times · Source

I'm currently trying to run the atom editor in the bash shell, from the fish shell. It's important that I run atom in bash because of how ide-haskell handles ghc-mod path resolution, and a few other standardization issues.

Here is how I was going at it:

#~/.config/fish/config.fish

function start-atom
  bash $HOME/lib/atom/bin/Atom/atom $argv
end

However, when I try running start-atom from fish, I get the following error:

/home/athan/lib/atom/bin/Atom/atom: /home/athan/lib/atom/bin/Atom/atom: cannot execute binary file

Even though I know this file is correct and executable. Any ideas? Thank you!

Answer

Mr. Llama picture Mr. Llama · Jan 8, 2015

When you run bash file_name it means you're trying to run file_name as a bash script.

Try this instead:

bash -c '$HOME/lib/atom/bin/Atom/atom "$@"' dummy $argv

The -c means "run this command with bash" instead of "run this script with bash".

As Charles pointed out in the comments, we have to do a bit of tweaking to pass the parameters to the command. We pass them to bash which will use them as positional parameters inside of the supplied command, hence the $@.