Minishell
Publicado por Marcelo R. Castelo Branco 17/04/2005
[ Hits: 12.968 ]
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;
}
POGRAMA EM C REGISTRO DE CADASTRO ALTERAR E REMOVER CLIENTES PRODUTOS
LazyDocker – Interface de Usuário em Tempo Real para o Docker
Instalando COSMIC no Linux Mint
Turbinando o Linux Mint: o poder das Nemo Actions
Inteligência Artificial no desenvolvimento de software: quando começar a usar?
O widget do Plasma 6 Área de Notificação
[Resolvido] Algo deu errado ao abrir seu perfil
Quando vocês pararam de testar distros? (14)
Problema com som no laptop (3)
Não estou conseguindo fazer funcionar meu Postfix na versão 2.4 no Deb... (2)









