解析/传递命令行参数bash脚本 - 之间有什么&QUOT的区别; $ @"和" $ * QUOT ;? [英] Parsing/passing command line arguments to a bash script - what is the difference between "$@" and "$*"?

查看:148
本文介绍了解析/传递命令行参数bash脚本 - 之间有什么&QUOT的区别; $ @"和" $ * QUOT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是bash脚本调用,并从任何位置执行的.jar 文件,而无需不断进入其显式路径。

I am using a bash script to call and execute a .jar file from any location without having to constantly enter its explicit path.

的.jar 要求在执行中指定的其他变量参数,因为这些可以是任何东西,他们不能硬codeD插入脚本。

The .jar requires additional variable parameters to be specified at execution, and as these can be anything, they cannot be hard coded into the script.

有3个变量中总,所述第一指定的2动作1的的.jar 是使,第二个指定的目标文件颁布关于此操作并第三指定一个文件,该文件的操作是创建的名称

There are 3 variables in total, the first specifies 1 of 2 actions that the .jar is to make, the second specifies a target file to enact this action on and the third specifies the name of a file that the action is to create.

我目前使用的脚本是:

#!/bin/bash  
java -jar "C:\path\to\file.jar" "$1" "$2" "$3"

我还不是很了解的bash脚本,但在寻找另一种答案我的困境(现已修复)我碰到$ @$ *引用命令行参数时。做更多的搜索把我带到这个网站:如何维基:如何读取命令行参数在bash脚本,但我不能,而无需万吨高级bash编程来趟这是我头上的方法找到这些参数任何固体信息。

I know very little about bash scripting, but while searching for another answer to my woes (now fixed) I came across "$@" and "$*" when referencing command line arguments. Doing more searching brought me to this site: How To Wiki: How to read command line arguments in a bash script, but I can't find any solid information about those arguments without having to wade through tons of advanced bash programming that is way above my head.

所以,现在,我已经永远天马行空,我的问题是比较简单的:

So now that I have rambled on forever, my question is relatively simple:

我可以取代$ 1$ 2$ 3$ @$ *,如果是的话这是更好的使用?

Can I replace "$1" "$2" "$3" with "$@" or "$*", and if so which is the better one to use?

还有什么,如果有的话,就是这些命令的区别?

Also what, if any, is the difference between those commands?

推荐答案

$ @对应$ 1$ 2$ 3 $ *对应$ 1 $ 2 $ 3,你做似乎没有需要。

"$@" corresponds to "$1" "$2" "$3" etc. "$*" corresponds to "$1 $2 $3" which you do not seem to need.

没有报价,没有什么区别,它们都对应于 $ 1 $ 2 $ 3 等。

Without quotes, there is no difference, they both correspond to $1 $2 $3 etc.

这篇关于解析/传递命令行参数bash脚本 - 之间有什么&QUOT的区别; $ @"和" $ * QUOT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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