Minishell
Publicado por Marcelo R. Castelo Branco 17/04/2005
[ Hits: 12.903 ]
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;
}
Jogo Simon (Genius) - com gráficos
Classe para manipulação e conversão de datas para std::string em C++
Modo Simples de Baixar e Usar o bash-completion
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
Instalando partes faltantes do Plasma 6
Adicionar botão "mostrar área de trabalho" no Zorin OS
Como montar um servidor de backup no linux
Estou tentando ser legalista, mas tá complicado! (9)
espelhar monitores nao funciona (2)
SQLITE não quer funcionar no LINUX LMDE6 64 com Lazaruz 4.2 64bit (n... (1)









