linux程序命令行选项的3种风格:unix、gnu、x toolkit
2024-09-30 16:01:35
In Unix-like systems, the ASCII hyphen-minus is commonly used to specify options. The character is usually followed by one or more letters. Two hyphen-minus characters (--) often indicate that the remaining arguments should not be treated as options, which is useful for example if a file name itself begins with a hyphen, or if further arguments are meant for an inner command. Double hyphen-minuses are also sometimes used to prefix "long options" where more descriptive option names are used. This is a common feature of GNU software. The getopt function and program, and the getopts command are usually used for parsing command-line options.
Unix 风格:单个减号 -
在选项需要加参数的时候,紧跟在选项后面即可(或者加空格)。比如登录 mysql server 的时候:
$ mysql -u root -p
或者
$ mysql -uroot -p
均可。这时,root 就是 u 的参数,表示使用 root 用户登录。另外加不加空格看程序怎么才处理了,没有明确的规定。
GNU 风格:双减号 --
使用两个连字符加上关键词(而不是单个字符)。这种风格的出现是因为有一些复杂的 GNU 程序,仅仅 26 个字母(或者算上大小写 52 个)不够使用而发展出来的。另外一个有点是容易理解,因为出现的不再是缩写的字母。选项参数可以使用空格分割也可以使用"="来分割。如:
$ ls --human-readable --sort=time
如果使用 Unix 风格,那么上条命令则是
$ ls -ht
是不是更加易读呢?
X toolkit 风格
这是一种比较不常见的风格,使用单个连字符加上关键词。只有 X 相关的程序才使用这种风格,一般不建议使用。
$ xeyes -display joesws:0 -geometry 1000x1000+0+0
看上去和 GNU 风格差不多,只是双连字符改成了单个连字符。
https://en.wikipedia.org/wiki/Command-line_interface#Arguments
最新文章
- AC自动机 HDU 3065
- 在iPhone上同时关闭语音控制和siri的方法
- BZOJ 3112: [Zjoi2013]防守战线 [单纯形法]
- IOS block 循环引用的解决
- 【USACO 2.1】The Castle
- ArrayList的使用方法【转载】
- Oracle利用数据泵迁移用户
- 使用WebFrom来模拟一些MVC的MODEL与View的数据交互功能
- 谷歌识图、google识图如何知道图片相似?
- 教你用.Net来玩微信跳一跳
- Vue-cropper 图片裁剪的基本原理
- Linux安装TeamViewer
- (8)Microsoft office Word 2013版本操作入门_制作传单海报
- JS 获取链接中的参数
- Oracle课程档案,第十二天
- JFinal项目部署到Weblogic注意事项
- python day04作业
- 读jQuery源码释疑笔记3
- 表迁移工具的选型-复制ibd的方法-传输表空间
- Working routine CodeForces - 706E (链表)