getopt使用例子
getopt是linux下获取程序启动参数的函数
int getopt(int argc, char * const argv[],
const char *optstring);
extern char *optarg;
extern int optind, opterr, optopt;
#include <stdlib.h>
#include <unistd.h>
using namespace std;
int main(int argc, char** argv)
{
int opt = 0;
while(-1 != (opt = getopt(argc, argv, "n:t:kl")))
{
switch(opt)
{
case 'n':
fprintf(stdout, "n:%s\n", optarg);
break;
case 't':
fprintf(stdout, "t:%s\n", optarg);
break;
case 'k':
fprintf(stdout, "k option get\n");
break;
case 'l':
fprintf(stdout, "l option get\n");
break;
}
}
return 0;
}
n:100
t:vi
k option get
l option get
smi /project/bm3.5/smi/test/zd/self>tg -n 100 -t vi -k -l
n:100
t:vi
k option get
l option get
smi /project/bm3.5/smi/test/zd/self>tg -n 100 -t -k -l
n:100
t:-k
l option get
smi /project/bm3.5/smi/test/zd/self>tg -n
tg: option requires an argument -- n
smi /project/bm3.5/smi/test/zd/self>tg -n -t
n:-t
tg: invalid option -- o
n:100
getopt使用例子的更多相关文章
- linux —— shell 编程(编程语法)
导读 本文为博文linux —— shell 编程(整体框架与基础笔记)的第4小点的拓展.(本文所有语句的测试均在 Ubuntu 16.04 LTS 上进行) 目录 再识变量 函数 条件语句 循环语句 ...
- getopt例子
(本例基于win7 + python3.4) import getopt, sys ''' getopt 模块专门用来处理命令行参数 函数 getopt(args, shortopts, longop ...
- getopt,getoptlong学习
getopt和getoptlong被用来解析命令行参数. 一.getopt #include <unistd.h> extern char *optarg; extern i ...
- [转]Python 命令行参数和getopt模块详解
FROM : http://www.tuicool.com/articles/jaqQvq 有时候我们需要写一些脚本处理一些任务,这时候往往需要提供一些命令行参数,根据不同参数进行不同的处理,在Pyt ...
- 【python】getopt使用
来源:http://blog.chinaunix.net/uid-21566578-id-438233.html 注意对比:[python]argparse模块 作者:limodou版权所有limod ...
- PHP函数getopt详解
短参数 它返回一个包含命令行参数的数组.比如,要获得-a -b 和-c的值,可以这么做: $arguments = getopt("a:b:c:"); 可以用下面的方式运行脚本(有 ...
- Python 命令行参数和getopt模块详解
有时候我们需要写一些脚本处理一些任务,这时候往往需要提供一些命令行参数,根据不同参数进行不同的处理,在Python里,命令行的参数和C语言很类似(因为标准Python是用C语言实现的).在C语言里,m ...
- 在 Perl 中使用 Getopt::Long 模块来接收用户命令行参数
我们在linux常常用到一个程序需要加入参数,现在了解一下 perl 中的有关控制参数的模块 Getopt::Long ,比直接使用 @ARGV 的数组强大多了.我想大家知道在 Linux 中有的参数 ...
- [Perl] Getopt 函数来接收用户参数的使用
我们在linux常常用到一个程序需要加入参数,现在了解一下perl中的有关控制参数的函数.getopt.在linux有的参数有二种形式.一种是–help,另一种是-h.也就是-和–的分别.–表示完整参 ...
随机推荐
- BZOJ2252: [2010Beijing wc]矩阵距离
题解: 我脑子里都是翔??? bfs一下就行了 我居然还想什么kd tree!真是too naive,,, #include<cstdio> #include<cstdlib> ...
- HNOI2010弹飞绵羊
不得不说块状数组好神奇的啊!这道题的标签可是splay的启发是合并(什么高大上的东西),竟然这么轻松的就解决了! var x,y,i,j,tot,n,m,ch:longint; f,k,l,bl,go ...
- ti processor sdk linux am335x evm /bin/setup-uboot-env.sh hacking
#!/bin/sh # # ti processor sdk linux am335x evm /bin/setup-uboot-env.sh hacking # 说明: # 本文主要对TI的sdk中 ...
- ubuntu - chrome 标题栏, 书签乱码 解决
只要修改/etc/fonts/conf.d/49-sansserif.conf这个文件就行了—— 打开/etc/fonts/conf.d/49-sansserif.conf这个文件: sudo ged ...
- POJ:最长上升子序列
Title: http://poj.org/problem?id=2533 Description A numeric sequence of ai is ordered if a1 < a2 ...
- sharepoint 2010 在aspx 写lambda 时错误
在sharepoint 2010 中,写lambda时,遇到错误.在aspx里面,写lambda表达式, 运行时报错,就不明道理了.经过百般测试,终于找到方法: 错误提示: "/" ...
- java 中的Exception RuntimeException 区别
在java的异常类体系中: 1.Error和RuntimeException是非检查型异常,其他的都是检查型异常; 2.所有方法都可以在不声明throws的情况下抛出RuntimeException及 ...
- context.Response.End()的用法和本质
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Web_C ...
- WPF MultiBinding 和 IMultiValueConverter
MultiBinding,描述附加到单个绑定目标属性的Binding对象的集合.可以指定多个数值绑定. IMultiValueConverter通过转换器使用MultiBingding对象,该对象讲根 ...
- [Everyday Mathematics]20150201
设数列 $\sed{a_n}$ 单调递减趋于零, 证明 $\dps{\vsm{n}a_n}$ 收敛当且仅当 $\dps{\vsm{n}3^k a_{3^k}}$ 收敛.