shell 是一个简单的 c 解释器。就像编写 ac 程序一样编写代码:
-> mysock = socket(2, 1, 0)
/* double check that these are right for AF_INET and SOCK_STREAM*/
-> myaddr = malloc(100)
-> m myaddr
/* fill in the fields according to the address you want to connect to */
-> connect(mysock, myaddr, myaddrlen)
/* I don't have a system handy now, but you can figure out
myaddrlen by writing a small C program to print out sizeof(sockaddr_in),
or just figure it out by hand looking at the header. */
现在您的套接字 fd 已连接、重定向并玩得开心。(在我看来,如果您要定期执行此操作,将其编码到 ac 程序中可能会更简单,您可以从 shell 运行该程序来为您完成所有设置。)