sh

function ba () {
echo $(basename "$1")
}

export -f ba
echo "a b/c"|xargs -I @ sh -c "ba '@'"



ba "$@"




#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>

int main(int argc, char *argv[])
{
int fd = open("a.txt", O_CREAT|O_APPEND|O_WRONLY, 0600);
if (fd < 0)
return 1;
for (int i = 0; i < argc; i++){
const char *p = argv[i];
int n = strlen(p);
write(fd, p, n);
write(fd, "\n", 1);
}
close(fd);
return 0;
}




#include <unistd.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
int fd = 0;
int n = 0;
char buf[100];
while ((n = read(fd, buf, sizeof (buf))) > 0) {
buf[n]=0;
printf("%s", buf);
}
//printf("\n%d\n", n);
return 0;
}




posted @ 2022-08-15 14:39  zJanly  阅读(93)  评论(0)    收藏  举报