目的:
linux系统下,
在shell终端中输入my_cmd1,回车,打印 ”hello,world!cmd1”;
在shell终端中输入my_cmd2,回车,打印 ”hello,world!cmd2”;
流程:
1.编写一个处理函数my_cmd.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int main(int argc, char *argv[])
{
if(!(strncmp(argv[0], "my_cmd1", 7)))
{
printf("hello,world!cmd1.\n");
}
else if(!(strncmp(argv[0], "my_cmd2", 7)))
{
printf("hello,world!cmd2.\n");
}
return 0;
}
2.编译生成可执行文件,my_cmd
3.复制到/bin/目录下
4.创建软连接:
ln -s my_cmd mycmd1
ln -s my_cmd mycmd2
5.在任意目录中,输入my_cmd1,即可打印"hello,world!cmd1."。
如果要在arm板上实现相同功能,则
1.同上1
2.同上2
3.解压原来的文件系统rootfs.tar.bz2,生成rootfs目录
5.把新生成的my_cmd拷贝至rootfs/bin下
6.在rootfs/bin下建立一个软连接:
ln -s my_cmd mycmd1
ln -s my_cmd mycmd2
7.重新压缩rootfs目录替换原来的rootfs.tar.bz2
8.打包烧写新的系统即可。