访问函数内Bash脚本的参数 [英] Access arguments to Bash script inside a function

查看:69
本文介绍了访问函数内Bash脚本的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在函数内部,$1 ... $n是传递给该函数的参数. 函数$1 ... $n之外是传递给脚本的参数.

Inside a function, $1 ... $n are the parameters passed to that function. Outside a function $1 ... $n are the parameters passed to the script.

我可以以某种方式访问​​传递给函数内部脚本的参数吗?

Can I somehow access the parameters passed to the script inside a function?

推荐答案

通常,您只需在调用时将它们作为参数传递给函数即可.

Usually you just pass them as parameters to the function at call time.

(较丑陋的)替代方法是将它们放在全局变量中.

The (uglier) alternative is to put them in global variables.

这篇关于访问函数内Bash脚本的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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