diff --git a/shell2 b/shell2 index 155bb78..c5c3806 100755 Binary files a/shell2 and b/shell2 differ diff --git a/shell2.c b/shell2.c index 720743b..9a88258 100644 --- a/shell2.c +++ b/shell2.c @@ -1,33 +1,34 @@ -#include #include -#include +#include #include #include -#include +#include +#include #include +#include #define clear() printf("\033[H\033[J") void init_shell() { - clear(); + clear(); - printf("\n\n\n\n******************************************"); - printf("\n\n\n\t****MY SHELL****"); - printf("\n\n\t-USE AT YOUR OWN RISK-"); - printf("\n\n\n******************************************"); + printf("\n\n\n\n******************************************"); + printf("\n\n\n\t****MY SHELL****"); + printf("\n\n\t-USE AT YOUR OWN RISK-"); + printf("\n\n\n******************************************"); - char* username = getenv("USER"); - printf("\n\nUSER is: @%s\n", username); - sleep(1); + char *username = getenv("USER"); + printf("\n\nUSER is: @%s\n", username); + sleep(1); - clear(); + clear(); } -int take_input(char* str) { - char* buf; +int take_input(char *str) { + char *buf; buf = readline("\n>>> "); - if(strlen(buf) != 0) { + if (strlen(buf) != 0) { add_history(buf); strcpy(str, buf); return 0; @@ -42,17 +43,33 @@ void print_dir() { printf("\nDir: %s", cwd); } -def execute(char** parsed) { +void execute_args(char **parsed) { pid_t pid = fork(); if (pid == -1) { printf("\nFailed forking child.."); return; } else if (pid == 0) { - + if (execvp(parsed[0], parsed) < 0) { + printf("\nCould not execute command.."); + } + exit(0); + } else { + wait(NULL); + return; } } +void open_help() { + puts("\n***Welcome to my shell help" + "\n-Use the shell at your own risk..." + "\nList of commands support:" + "\n>cd" + "\n>ls" + "\n>exit" + "\n>all other general commands available in UNIX shell"); +} + int main() { init_shell(); }