简体   繁体   English

如何从以别名运行的脚本中读取 arguments

[英]How can I read arguments from script that is being run in a alias

Let say I have an alias alias kubectl='bash script.sh && kubectl' Is there any way to read passed arguments in script.sh eg.假设我有一个别名alias kubectl='bash script.sh && kubectl'有什么方法可以读取script.sh中传递的 arguments 例如。 If I run kubectl get pods , how to read "get" and "pods" in script.sh如果我运行kubectl get pods ,如何在 script.sh 中读取“get”和“pods”

The millennium long advice is to use a function instead of alias.千年长的建议是使用 function 而不是别名。

how to read "get" and "pods" in script.sh如何在 script.sh 中读取“get”和“pods”

Not possible with an alias, with a function just pass the arguments to script.sh.使用别名是不可能的,使用 function 只需将 arguments 传递给 script.sh。

kubectl() {
   bash script.sh "$@" &&
   command kubectl "$@"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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