[英]Calling another function in fish shell
我收到此有关如何在zsh的功能转换成鱼功能出色答卷。 现在我还有一个问题。 如何从另一个函数调用该函数,传递参数?
我试过这个:
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
但我得到“env:ogf:没有这样的文件或目录”。
目标只是为这次执行更改EDITOR
环境变量,然后调用ogf
。
env
命令只能运行其他外部命令。 它不能调用shell内置函数或函数; 无论外壳是鱼,还是其他东西。 解决方案是使用--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
另一种选择是编写您的函数以使用其自己的参数,如下所示:
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
也许这是一个关于如何在传递参数时调用另一个函数的更简单的例子:
function foo
bar "hello" "world"
end
function bar
echo $argv[1]
echo $argv[2]
end
然后调用foo
将打印:
$ foo
hello
world
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.