如何通过包装器重新获得对命令的控制?
我的公司习惯于在启动程序命令周围放置包装器,例如:
“MGC_HOME/bin/dmgr_ic”,
它将启动 MGC 环境,允许用户简单地键入“dmgr_ic”,它将检查一些环境变量并加载程序你。这些包装器很有用,但我想在原始命令中添加一些选项,例如
MGC_HOME/bin/dmgr_ic -geometry 800x600+0+0
来调整放置不当的窗口的大小。有什么想法吗?我不能以任何方式接触原始包装,也不想制作我自己的副本或版本。如果简单地使用包装器并以某种方式捕获有问题的命令并对其进行修改,那就太好了。
谢谢。
My company has a habit of putting wrappers around their startup program commands such as:
'MGC_HOME/bin/dmgr_ic'
which would start the MGC environment, allowing one to simply type 'dmgr_ic' and it will check some environment variables and load the program for you. These wrappers are useful, but I would like to add some options to the original command, such as
MGC_HOME/bin/dmgr_ic -geometry 800x600+0+0
to resize a poorly placed window. Any ideas? I cannot touch the original wrapper in any way and don't want to make my own copy or version of it. It would be nice to simply use the wrapper and somehow capture the command in question and modify that.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
涉及修改包装器脚本的选项 - 这些想法足够好,他们可能会愿意更改它们:
添加由新的
-xargs xyz
包装器参数提供给包装器的参数(最佳)添加通过特殊环境变量提供给包装器的参数
添加通过
~/.dmgr_ic_rc
文件提供给包装器的参数涉及的选项不修改包装器脚本:
创建一个 Perl 脚本(称为
dmgr_ic
),将当前包装器复制到/tmp
中,对其进行修改以添加-xargs
选项,并调用该临时副本。这不是一个好主意,但可行。-
Options involving modification of wrapper script(s) - the ideas are good enough that they might buy into changing them:
Add parameters supplied to the wrapper by a new
-xargs xyz
wrapper parameter (best)Add parameters supplied to the wrapper via a special environmental variable
Add parameters supplied to the wrapper via a
~/.dmgr_ic_rc
fileOptions involving NOT modifying wrapper scripts:
Create a Perl script (called
dmgr_ic
) that copies the current wrapper into/tmp
, modifies it to add the-xargs
option, and calls that temporary copy. NOT a good idea but works.-
这些包装脚本是否非常复杂,或者只是一个衬垫?
可以运行
set -xv
,然后使用bash -n
运行包装器脚本。这不会执行该命令,但会打印出应该执行的内容,我假设可能是最后一行。然后,您可以获取实际执行的命令,并将您自己的内容附加到其中。这将涉及包装包装器脚本。
他们需要更改包装脚本并使其更加灵活。我不介意默认值,但允许它们被命令行参数覆盖。例如,默认值可能是:
但是,如果我这样做,
脚本将执行:
这可以通过创建 Perl 包装器并使用 Getopt::Long.一个快速而肮脏的实现可能看起来像这样:
不是 100% 有效的代码,但你应该明白这个想法。
这个想法是您需要小心像
-fubar
这样的可选参数。在上面,我将$fubar
与参数和值(如果有参数$fubar
)结合起来。另一种选择是使用哈希来存储参数(可以使用 GetOptions),然后通过哈希构建命令行参数。无论如何,让包装器更加灵活并提供所需的默认值和覆盖这些默认值的能力并不难。
Are these wrapper scripts very complex, or just one liners?
It might be possible to run
set -xv
, then run the wrapper script withbash -n
. This won't execute the command, but will print out what is suppose to be executed which I'm assuming is probably the last line.Then, you could take the command that's actually executed, and append your own stuff to it. That would involve wrapping the wrapper script.
They need to change the wrapper script and make them more flexible. I don't mind the defaults, but allow them to be overwritten by command line parameters. For example, the default might be:
However, if I did this
The script would execute:
This could easily be done by creating a Perl wrapper and using Getopt::Long. A quick and dirty implementation might look like this:
Not 100% that's valid code, but you should get the idea.
The idea is that you need to be careful of optional parameters like
-fubar
. In the above, I combine$fubar
with the parameter and the value if there is a parameter$fubar
. Another option is to use a hash for storing the parameters (possible with GetOptions), and then building the command line parameter via the hash.Anyway, it's not that hard to make wrappers more flexible and provide both the desired defaults and the ability to override those defaults.
尝试
文本文件
然后创建 MGC_HOME/bin/dmgr_ic 作为包含then 的
Try
Then create MGC_HOME/bin/dmgr_ic as a text file containing
Then