我正在尝试使用 C 系统函数编写别名,这是代码
if (argc <= 3) {
printf("Program Usage: ./executable alias > or < or >> or &\n");
}
else {
if (strcmp(argv[1],"alias") == 0) {
if (strcmp(argv[2], "redirect") == 0) {
char y[] = "=\">\"";
char *xs = strcat(argv[1], " ");
char *x = strcat( xs, strcat(argv[3], y));
printf("%s\n",x);
int status = system(x);
printf("%d\n", status);
}
else {
printf("You've not entered proper symbol\n");
}
}
else {
printf("You've not entered the shell property as alias\n");
}
}
运行程序的一般方式是
./a.out alias redirect custom_alias_name
此外,系统函数返回 0,但是当我使用 alias 命令检查时,它不显示当前别名。