Fish shell 和通过 `function` 从 bash 执行程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27847300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The fish shell and executing programs from bash through `function`
提问by Athan Clark
I'm currently trying to run the
atom editorin 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.
我目前正试图运行
原子编辑器中bash
壳,从fish
壳。由于 ide-haskell 如何处理路径解析以及其他一些标准化问题,我atom
参与其中很重要。bash
ghc-mod
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:
但是,当我尝试start-atom
从运行时fish
,出现以下错误:
/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!
即使我知道这个文件是正确且可执行的。有任何想法吗?谢谢!
回答by Mr. Llama
When you run bash file_name
it means you're trying to run file_name
as a bash script.
当您运行时,bash file_name
这意味着您正在尝试file_name
作为 bash 脚本运行。
Try this instead:
试试这个:
bash -c '$HOME/lib/atom/bin/Atom/atom "$@"' dummy $argv
The -c
means "run this commandwith bash" instead of "run this script with bash".
的-c
意思是“运行此命令在bash”,而不是“使用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 $@
.
正如查尔斯在评论中指出的那样,我们必须做一些调整才能将参数传递给命令。我们将它们传递给它们bash
,将它们用作所提供命令内的位置参数,因此$@
.
回答by glenn Hymanman
should be: bash -c '$HOME/lib/atom/bin/Atom/atom "$@"' _ $argv
应该: bash -c '$HOME/lib/atom/bin/Atom/atom "$@"' _ $argv
The underscore will become bash's $0
下划线将成为 bash 的 $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.
如果您需要该 bash 会话来加载您的配置,请将其设为登录 shell。
So, bottom line: ~/.config/fish/functions/start-atom.fish
所以,底线: ~/.config/fish/functions/start-atom.fish
function start-atom
bash -l -c '$HOME/lib/atom/bin/Atom/atom "$@"' _ $argv
end