如何通过传递给我的bash脚本我的一个功能,所有参数? [英] How to pass all arguments passed to my bash script to a function of mine?

查看:84
本文介绍了如何通过传递给我的bash脚本我的一个功能,所有参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我已经定义的函数ABC()将处理所有analising传递给我的脚本的参数相关的逻辑。

Let's say I have defined a function abc() that will handle all the logic related to analising the arguments passed to my script.

我如何通过我的bash脚本已收到它的所有论据?则params的数量是可变的,所以我不能只是很难code通过这样的参数:

How can I pass all arguments my bash script has received to it? The number of params is variable, so I can't just hardcode the arguments passed like this:

abc $1 $2 $3 $4

编辑:更重要的是,有没有办法为我的函数可以访问脚本参数变量

edit: Better yet, is there any way for my function to have access to the script arguments' variables?

推荐答案

忌讳:当使用 $ @ ,你应该(几乎)总是把它放在双引号为了避免争论misparsing带空格:

Pet peeve: when using $@, you should (almost) always put it in double-quotes to avoid misparsing of argument with spaces in them:

abc "$@"

这篇关于如何通过传递给我的bash脚本我的一个功能,所有参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆