如何复制bash脚本的参数以进行单独处理? [英] How can the arguments to bash script be copied for separate processing?

查看:49
本文介绍了如何复制bash脚本的参数以进行单独处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要修改现有的bash脚本,但我想将其所需的更改封装到一个函数中,而又不影响它对'$ @'变量的操作方式。

There is an existing bash script I need to modify, but I want to encapsulate the changes required to it in a function without affect how it manipulates the '$@' variable.

我的想法是将参数字符串复制到新变量中并分别提取所需的参数,但是似乎应用 shift仅在 $ @ 变量并对其进行永久性修改。

My idea is to copy the argument string to a new variable and extract the arguments required separately, but it seems that applying the 'shift' operates only on the $@ variable and modifies it permanently.

是否可以模拟 $ @ 变量及其相关处理

Is there way to emulate the processing of the $@ variable and its related functions on a normal string?

推荐答案

您可以保留 $ @ 放入BASH数组中:

You can preserve the $@ into a BASH array:

args=("$@")

并随时从BASH数组 $ {args [@]} 构造/检索/处理原始参数

And construct/retrieve/process original arguments anytime from BASH array "${args[@]}"

这篇关于如何复制bash脚本的参数以进行单独处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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