Linux的:我如何委派使用脚本异国情调的命令行参数? [英] Linux: How do I delegate exotic commandline arguments using a script?

查看:156
本文介绍了Linux的:我如何委派使用脚本异国情调的命令行参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个包装bash脚本,和所有参数传递给调用的程序。我很肯定,这正常工作:

 #!/ bin / sh的
someProgam $ @

但经过异国参数时(在引号空,转义,...)失败。

例如:没有包装脚本, someProgram在参数1 23 结果,点击
[1〜2] [3] 。结果
但是从脚本调用,我得到 [1] [2] [3 ]

括号只是用于可视化。

注:这是一个Java程序,它调用。但我认为这并不重要。


解决方案

 #!/ bin / sh的
someProgram$ @

又见特殊参数的bash文档

BTW1,$ @不是特定打坏。你也许可以依靠跨平台$ @ SH 来在任何地方运行的脚本。

BTW2,万一出现这种情况是在脚本中的最后一行,可以节省您的操作系统的几个字节,并通过更改行像

在进程表中的条目

  EXEC someProgram$ @

I want to write a wrapper bash script, and to pass all arguments to a called program. I was very sure, that this works correctly:

#!/bin/sh
someProgam $@

But when passing exotic arguments (empty, unescaped, in quotes, ...) this fails.

For example: without the wrapper script, someProgram "1 2" 3 results in the arguments
[1 2] and [3].
But called from the script, I get [1], [2], [3].

Braces are just for visualization.

NOTE: It's a Java program, which is called. But I think it doesn't matter.

解决方案

#!/bin/sh
someProgram "$@"

See also the bash docs on special parameters.

BTW1, "$@" is not specific to bash. You can probably rely on "$@" in cross-platform sh scripts to be run just about anywhere.

BTW2, in case this happens to be the last line in that script, you can save your operating system a few bytes and an entry in the process table by changing the line to something like

exec someProgram "$@"

这篇关于Linux的:我如何委派使用脚本异国情调的命令行参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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