如何在.bash_profile 中为带参数的`curl` 制作别名/函数?

Dan*_*Dan 4 mac bash terminal.app curl .bash-profile

我发现这个提示超级有用,使用curl恢复中断的文件复制。

完整的语法是:

curl -C - -O file:///Volumes/path/to/file
Run Code Online (Sandbox Code Playgroud)

我想添加一个别名或函数调用resume到我的.bash_profile(在 Mac 上),以便我可以使用类似的东西

resume /Volumes/disk1/file
Run Code Online (Sandbox Code Playgroud)

我打算尝试类似的东西

function resume() { ... }
Run Code Online (Sandbox Code Playgroud)

但我不确定如何使用file:///前缀传递参数。

Ign*_*ams 5

函数就像脚本一样接收参数,因此您可以使用$1来引用传递的第一个参数:

resume () {
  curl -C - -O "file://$1"
}
Run Code Online (Sandbox Code Playgroud)

请注意,您不需要两者function 括号;任何一个都告诉 bash 它是一个函数。

  • 您可以在参数 `curl -C - -O "file://$1"` 周围加上引号 (2认同)