简体   繁体   中英

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

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!

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 $@ .

should be: bash -c '$HOME/lib/atom/bin/Atom/atom "$@"' _ $argv

The underscore will become bash's $0

A demo:

$ function test_bash_args
      bash -c 'printf "%s\n" "$@"' _ $argv
  end
$ test_bash_args one two three
one
two
three

If you need that bash session to load your configs, make it a login shell.

So, bottom line: ~/.config/fish/functions/start-atom.fish

function start-atom
    bash -l -c '$HOME/lib/atom/bin/Atom/atom "$@"' _ $argv
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM