是否有标准的Linux命令行开关和参数? [英] Are there standards for Linux command line switches and arguments?

查看:94
本文介绍了是否有标准的Linux命令行开关和参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是更多关于调用一个程序,比任何语言或解析器(虽然我相信解析器库的选择可以依赖于此)。看,我使用了很多Linux命令行实用程序。还有一些明显的模式; - 在短选项的单个字母之前,多个不带参数的选项可以组合, - 在选项的长版本之前,等等。

This is more about the invocation of a program, than any language or parser (though I'm sure choice of parser library can depend on this). See, I've used a lot of Linux command-line utilities. And there are some obvious patterns; '-' precedes a single letter for short options, multiple options that don't take arguments can be combined, '--' precedes long versions of options, and so on.

但是,在某些情况下,大写可用于取消选项。因此,'-d'可能意味着作为守护程序运行,但是'-D'将不作为守护程序运行。 (为什么不忽略该选项,如果你不想要它?这是从来不清楚,但它实际上是相当普遍,所以我认为必须有一些理由。)但在一些程序,资本是一个完全不相关的选择;如果'-d'作为守护程序运行,'-D'可能是启用调试模式。这背后是否有某种主要的原则,这是最好的选择?

However, in some cases, capitalization is used to invert an option. So, '-d' might mean to run as a daemon, but '-D' would be to not run as a daemon. (Why not just omit the option if you don't want it? That's never been clear, but it's actually rather common, so I figure there must be some reason.) But in some programs, a capital is a completely unrelated option; if '-d' is run as daemon, '-D' might be to enable debug mode. Is there some kind of overarching principal behind this, and which is the best to choose? Or are we just dealing with "whatever works"?

还有一些命令,除了(或替代)带有参数的选项,只需要一些参数。 cp是一个很好的例子;除了几个很少使用的切换,它接收的最后一个参数被假定为目的地,并且选项列表和目的地之间的任何参数被推定为源。是否有一个经验法则,当它依赖顺序,而不是使用显式选项标志与参数?

There are also some commands that, in addition to (or instead of) options with arguments, just take lone arguments. cp is a good example of this; aside from a couple rarely used toggles, the last argument it receives is presumed to be the destination, and any arguments between the option list and the destination are presumed to be sources. Is there a rule of thumb when it's "okay" to rely on order like that, instead of using explicit option flags with arguments?

推荐答案

p>一般,是的。

  • IEEE
  • GNU getopt

这篇关于是否有标准的Linux命令行开关和参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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