私はCで単純なUnixシェルを書いています。これが私がこれまでに持っているものです。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main() {
char x[256], y[256], z[256];
while (1) {
getcwd(y, sizeof(y));
printf("%s$ ", y);
fgets(x, sizeof(x), stdin);
if (x[0] == 'c' && x[1] == 'd' && x[2] == ' ') {
sscanf(x, "cd %s", &z);
chdir(z);
}
else if (strcmp(x, "exit\n") == 0) break;
else system(x);
}
return 0;
}
私がやりたいのは、チルダ文字(〜)と$HOMEを交換可能にすることです。簡単な検索と置換機能でこれを実行できると思いました。誰かがそのようなことを知っていますか?