Minishell
Publicado por Marcelo R. Castelo Branco 17/04/2005
[ Hits: 12.977 ]
Um minishell desenvolvido em C.
As bibliotecas abaixo devem estar instaladas:
types.h
stat.h
fcntl.h
unistd.h
stdio.h
string.h
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
char cmd[512];
char dir[4096];
char *argv[3];
int pid;
int main(void)
{
while (1) {
printf("[Crasher]$ ");
//escreve o prompt na tela.
fgets(cmd, 511, stdin);
cmd[strlen(cmd) - 1] = 0;
// troca o enter = \n por um novo {FONTE} = 0
if (strcmp(cmd, "exit") == 0)
// se o resultado da comparação for 0 = V finaliza o shell
exit (0);
else {
argv[0] = strtok(cmd, " ");
argv[1] = strtok(NULL, " ");
argv[2] = NULL;
if (strcmp(argv[0], "pwd") == 0) {
getcwd(dir, 4096);
printf("%s\n", dir);
}
else if (strcmp(argv[0], "cd") == 0) {
if (chdir(argv[1]) != 0)
printf("Caminho inválido!\n");
}
else {
pid = fork();
if (pid == 0) {
if (execvp(argv[0], argv) == -1) {
printf("Comando inválido\n");
exit (0);
}
}
else {
wait();
}
}
}
}
return 0;
}
Thread, Courses, Shell e Aquivo
Controle de estoque com listas
Gentoo: detectando impressoras de rede e como fixar uma impressora por IP
Como o GNOME conseguiu o feito de ser preterido por outras interfaces gráficas
Gentoo binário em 2026: UEFI, LUKS, Btrfs e Systemd
Trabalhando Nativamente com Logs no Linux
Jogando Daikatana (Steam) com Patch 1.3 via Luxtorpeda no Linux
Por que sua empresa precisa de uma PKI (e como automatizar EMISSÕES de certificados via Web API)
Instalando NoMachine no Gentoo com Systemd (acesso Remoto em LAN)
Gentoo: Trocando wpa_supplicant pelo iwd no NetworkManager (Systemd)
Instalar Linux em notebook Sony Vaio VPCEG13EB (10)
Vou destruir sua infância:) (6)
Quando vocês pararam de testar distros? (24)









