[英]Calling another function in fish shell
I received this excellent answer on how to convert a zsh function to a fish function.我收到此有关如何在zsh的功能转换成鱼功能出色答卷。 Now I have another question.
现在我还有一个问题。 How do I call that function from another function, passing on the argument?
如何从另一个函数调用该函数,传递参数?
I have tried this:我试过这个:
function ogf
echo "Cloning, your editor will open when clone has completed..."
source (env TARGET_DIRECTORY=~/students EDITOR=$EDITOR clone_git_file -ts $argv[1] | psub)
end
function wogf
env EDITOR=webstorm ogf "$argv[1]"
end
but I get "env: ogf: No such file or directory".但我得到“env:ogf:没有这样的文件或目录”。
The goal is only to change the EDITOR
environment variable for this one execution, and then call ogf
.目标只是为这次执行更改
EDITOR
环境变量,然后调用ogf
。
The env
command can only run other external commands. env
命令只能运行其他外部命令。 It cannot call shell builtins or functions; 它不能调用shell内置函数或函数; regardless whether the shell is fish, bash, or something else.
无论外壳是鱼,还是其他东西。 The solution is to define the function being called with the
--no-scope-shadowing
flag and use set -l
in the calling function: 解决方案是使用
--no-scope-shadowing
标志定义要调用的函数,并在调用函数中使用set -l
:
function ogf --no-scope-shadowing
echo "Cloning, your editor will open when clone has completed..."
source (env TARGET_DIRECTORY=~/students EDITOR=$EDITOR clone_git_file -ts $argv[1] | psub)
end
function wogf
set -l EDITOR webstorm
ogf $argv
end
Another option would be to write your function to use its own arguments, as follows:另一种选择是编写您的函数以使用其自己的参数,如下所示:
function ogf
echo "Cloning, your editor will open when clone has completed..."
source (env TARGET_DIRECTORY=~/students EDITOR=$argv[2] clone_git_file -ts $argv[1] | psub)
end
function wogf
ogf $argv[1] 'webstorm'
end
Maybe this is a simpler example on how to call another function while passing arguments:也许这是一个关于如何在传递参数时调用另一个函数的更简单的例子:
function foo
bar "hello" "world"
end
function bar
echo $argv[1]
echo $argv[2]
end
Then calling foo
will print:然后调用
foo
将打印:
$ foo
hello
world
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.