Minishell
Publicado por Marcelo R. Castelo Branco 17/04/2005
[ Hits: 12.995 ]
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;
}
AIMG-mostrar imagem fraquimentada em pontos aleatórios
Arquivos utilizados no artigo: "Desenvolvendo um plugin para o XMMS"
Berry Bank: Criando um Banco Digital Gamificado para seus Filhos com Gentoo, Flask e Tailscale
Papagaiando o XFCE com temas e recursos
Instale o DOOM Retro no Gentoo facilmente via Overlay
Steam (Flatpak) rodando jogos em partição NTFS
O dock Plank + U-Launcher deixam qualquer desktop mais produtivo
Instalar Linux em notebook Sony Vaio VPCEG13EB (17)
Alguém tem que acabar com ANATEL!!! (10)
O que você está ouvindo agora? [2] (229)









