From 0dee6738ecd3f3ff32919964adfc1ad63519faf1 Mon Sep 17 00:00:00 2001 From: wrightkhlebisol Date: Thu, 20 Jul 2023 17:32:18 +0100 Subject: [PATCH 01/53] proto remove value --- main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.h b/main.h index 8f5bb27..981c50e 100644 --- a/main.h +++ b/main.h @@ -40,7 +40,7 @@ char *_strdup(char *str); /** char *strtok(char *str, char *sep); */ envstruct *insert_end(envstruct *head, char *key, char *value); char *get_value(envstruct *head, char *key); - +int remove_value(envstruct *head, char *key); void clean_up(void); void sig_int_handler(int signum); From 8395bfd059fe2ef28ff965c9d5648546f0e27634 Mon Sep 17 00:00:00 2001 From: wrightkhlebisol Date: Thu, 20 Jul 2023 17:32:49 +0100 Subject: [PATCH 02/53] remove value at key --- linkedlist.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/linkedlist.c b/linkedlist.c index 1075afe..e4812fc 100644 --- a/linkedlist.c +++ b/linkedlist.c @@ -22,10 +22,42 @@ char *get_value(envstruct *head, char *key) if (head == NULL) return (NULL); + if ((head->next == NULL) && (head->key == key)) + return (head->value); + while (head->next != NULL) { if (head->key == key) return (head->value); - head++; + head = head->next; + } + + return (NULL); +} + +int remove_value(envstruct *head, char *key) +{ + envstruct *previous = NULL, *current = NULL, *next_node = NULL; + + if (head == NULL) + return (NULL); + + if ((head->next == NULL) && (head->key == key)) + { + head = NULL; + return (0); } + + while (head->next != NULL) + { + if (head->key == key) + { + previous->next = next_node + current->next = NULL; + return (0); + } + previous = head; + head = head->next; + } + return (1); } From b845793070532bf48cf503ac09b01ead792eba0e Mon Sep 17 00:00:00 2001 From: wrightkhlebisol Date: Sat, 22 Jul 2023 04:23:45 +0100 Subject: [PATCH 03/53] fix struct next --- main.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.h b/main.h index 981c50e..2233e26 100644 --- a/main.h +++ b/main.h @@ -15,8 +15,9 @@ typedef struct env_var { char *key; char *value; - env_var *next; -} envvar; + struct env_var *next; +} envstruct; +envstruct env_head = NULL; extern char **environ; char *lineptr = NULL; From 345b891c7336db889138c6fbbf435ab805b0b650 Mon Sep 17 00:00:00 2001 From: wrightkhlebisol Date: Sat, 22 Jul 2023 04:24:21 +0100 Subject: [PATCH 04/53] add node to list --- main.c | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/main.c b/main.c index d34f415..0957462 100644 --- a/main.c +++ b/main.c @@ -17,7 +17,7 @@ int main(void) label: if (isatty(fileno(stdin))) printf("$ "); - + _getline(); /** lineptr and numbytes accessed and modified from the he ader file and updated here */ printf("25\n"); @@ -106,7 +106,7 @@ char *_getline(void) * @cmd: the command checked * * Return: 0 or 1 -*/ + */ int is_builtin_cmd(char *cmd) { int i = 0; @@ -128,7 +128,7 @@ int is_builtin_cmd(char *cmd) * @argv: argument vector - points to arguments entered * * Return: void -*/ + */ void exec_builtin_cmd(char **argv) { if (strstr(argv[0], "exit") == argv[0]) @@ -160,7 +160,7 @@ void exec_builtin_cmd(char **argv) * @envp: argument variable * * Return: void -*/ + */ void exec_executable_cmd(char *cmd, char **argv, char **envp) { printf("334\n"); @@ -196,17 +196,17 @@ void exec_executable_cmd(char *cmd, char **argv, char **envp) * exit_cmd - exits/terminates the shell * * Return: void -*/ -void exit_cmd(void) + */ +void exit_cmd(int exit_code) { - exit(0); + exit(exit_code); } /** * env_cmd - lists all environment variables * * Return: void -*/ + */ void env_cmd(void) { int i = 0; @@ -218,12 +218,28 @@ void env_cmd(void) } } +void init_env_list() +{ + env_head = malloc(sizeof(envstruct)); + + while (*environ != NULL) + { + while( token != NULL ) { + printf( " %s\n", token ); //printing each token + token = strtok(NULL, " "); + } + insert_end(); + + *environ++; + } +} + /** * setenv_cmd - sets environment variable * @argv: argument vector * * Return: void -*/ + */ void setenv_cmd(char **argv) { @@ -234,7 +250,7 @@ void setenv_cmd(char **argv) * @argv: argument vector * * Return: void -*/ + */ void unsetenv_cmd(char **argv) { @@ -245,7 +261,7 @@ void unsetenv_cmd(char **argv) * @argv: argument vector * * Return: void -*/ + */ void cd_cmd(char **argv) { @@ -258,7 +274,7 @@ void cd_cmd(char **argv) * @str: the string to be dublicated * * Return: string or NULL -*/ + */ char *_strdup(char *str) { printf("251\n"); @@ -285,7 +301,7 @@ char *_strdup(char *str) * @cmd: commands (tokens) * * Return: void -*/ + */ char *check_cmd(char *cmd) { if (cmd[0] == '/') @@ -347,7 +363,7 @@ char *check_cmd(char *cmd) * @envp: argument variable * * Return: void -*/ + */ void execve_cmd(char *cmd, char **argv, char **envp) { printf("324\n"); @@ -364,7 +380,7 @@ void execve_cmd(char *cmd, char **argv, char **envp) * clean_up - frees the lineptr upon exit * * Return: void -*/ + */ void clean_up(void) { if (lineptr != NULL) @@ -376,7 +392,7 @@ void clean_up(void) * @signum: the signal passed * * Return: void -*/ + */ void sig_int_handler(int signum) { From 451c6291da1f0d79c8931ad540a688a2cb79a3e4 Mon Sep 17 00:00:00 2001 From: wrightkhlebisol Date: Sat, 22 Jul 2023 04:25:01 +0100 Subject: [PATCH 05/53] remove value from node --- linkedlist.c | 57 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/linkedlist.c b/linkedlist.c index e4812fc..68b3e0d 100644 --- a/linkedlist.c +++ b/linkedlist.c @@ -1,46 +1,60 @@ #include "main.h" -envstruct *insert_end(envstruct *head, char *key, char *value) +envstruct *insert_end(char *key, char *value) { - if (head == NULL) + envstruct *new_node = malloc(sizeof(envstruct)); + + if (new_node == NULL) return (NULL); - envstruct new_var; + new_node->key = key; + new_node->value = value; + new_node->next = NULL; - new_var->key = *key; - new_var->value = *value; - new_var->next = NULL; + if (head == NULL) + { + head = new_node; + free(new_node); + return (head); + } while (head->next != NULL) - head++; + head = head->next; - head->next = new_var; + head->next = new_node; + free(new_node); + return (head); } -char *get_value(envstruct *head, char *key) +char *get_value(char *key) { + envstruct *temp = NULL; + if (head == NULL) return (NULL); - - if ((head->next == NULL) && (head->key == key)) - return (head->value); - - while (head->next != NULL) + + printf("%s 0", head->value); + temp = head; + while (temp != NULL) { - if (head->key == key) - return (head->value); - head = head->next; + if (temp->key == key) + return (temp->value); +// printf("%s 1", temp->value); + temp = temp->next; } + if (temp->key == key) + return (temp->value); + return (NULL); } -int remove_value(envstruct *head, char *key) +int remove_value(char *key) { envstruct *previous = NULL, *current = NULL, *next_node = NULL; if (head == NULL) - return (NULL); + return (1); if ((head->next == NULL) && (head->key == key)) { @@ -48,12 +62,11 @@ int remove_value(envstruct *head, char *key) return (0); } - while (head->next != NULL) + while (head != NULL) { if (head->key == key) { - previous->next = next_node - current->next = NULL; + previous->next = next_node; return (0); } previous = head; From 15bc18a02e9952f81215cf403f81db2367b30ff3 Mon Sep 17 00:00:00 2001 From: wrightkhlebisol Date: Sat, 22 Jul 2023 04:45:15 +0100 Subject: [PATCH 06/53] Tokenize env --- main.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 96e7eda..df67c60 100644 --- a/main.c +++ b/main.c @@ -223,11 +223,12 @@ void init_env_list() while (*environ != NULL) { - while( token != NULL ) { - printf( " %s\n", token ); //printing each token - token = strtok(NULL, " "); + char *key = strtok(environ, "="), *val = NULL; + while( environ != NULL ) { + val = strtok(NULL, " "); + printf( "%s, %s\n", key, val); //printing each token } - insert_end(); + insert_end(key, val); *environ++; } From 44a1c977750217498f8bf933742f835a8d0438dd Mon Sep 17 00:00:00 2001 From: wrightkhlebisol Date: Sat, 22 Jul 2023 04:48:00 +0100 Subject: [PATCH 07/53] proto correct return for exis_cmd --- main.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.h b/main.h index 853c2c9..32a57ab 100644 --- a/main.h +++ b/main.h @@ -17,11 +17,11 @@ typedef struct env_var { char *value; struct env_var *next; } envstruct; -envstruct env_head = NULL; +envstruct *head = NULL; extern char **environ; char *lineptr = NULL; -void exit_cmd(void); +void exit_cmd(int); void env_cmd(void); void setenv_cmd(char **argv); From a8b8211594f3afbd4d1dddb21b874dce948ab90d Mon Sep 17 00:00:00 2001 From: wrightkhlebisol Date: Sat, 22 Jul 2023 04:53:17 +0100 Subject: [PATCH 08/53] return exit code --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index df67c60..29da916 100644 --- a/main.c +++ b/main.c @@ -132,7 +132,7 @@ void exec_builtin_cmd(char **argv) { if (strstr(argv[0], "exit") == argv[0]) { - exit_cmd(); + exit_cmd(atoi(argv[1])); } if (strstr(argv[0], "env") == argv[0]) { From 435b9df9d1801569d63202fb32fc1ce902631971 Mon Sep 17 00:00:00 2001 From: wrightkhlebisol Date: Sat, 22 Jul 2023 04:55:13 +0100 Subject: [PATCH 09/53] fix undeclared var head --- main.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/main.c b/main.c index 29da916..9482e57 100644 --- a/main.c +++ b/main.c @@ -219,8 +219,6 @@ void env_cmd(void) void init_env_list() { - env_head = malloc(sizeof(envstruct)); - while (*environ != NULL) { char *key = strtok(environ, "="), *val = NULL; From d89f8489693e10fc00e3a9943f994e9c3f434371 Mon Sep 17 00:00:00 2001 From: wrightkhlebisol Date: Tue, 25 Jul 2023 14:01:12 +0100 Subject: [PATCH 10/53] pointer for strtok --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 9482e57..e6c738a 100644 --- a/main.c +++ b/main.c @@ -221,7 +221,7 @@ void init_env_list() { while (*environ != NULL) { - char *key = strtok(environ, "="), *val = NULL; + char *key = strtok(*environ, "="), *val = NULL; while( environ != NULL ) { val = strtok(NULL, " "); printf( "%s, %s\n", key, val); //printing each token From 7f76c21775c9ff1845d536e93258a29104814655 Mon Sep 17 00:00:00 2001 From: wrightkhlebisol Date: Tue, 25 Jul 2023 14:02:35 +0100 Subject: [PATCH 11/53] doc struct --- main.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/main.h b/main.h index 32a57ab..587a23f 100644 --- a/main.h +++ b/main.h @@ -12,14 +12,21 @@ #include #include -typedef struct env_var { +/** + * env_var - Node for env variables + * @key: + * @value: + * @next: + */ +typedef struct env_var +{ char *key; char *value; struct env_var *next; } envstruct; -envstruct *head = NULL; +envstruct *head; extern char **environ; -char *lineptr = NULL; +char *lineptr; void exit_cmd(int); void env_cmd(void); From 271b1862a3ca3f9868c43e305ddc66227f5918b2 Mon Sep 17 00:00:00 2001 From: wrightkhlebisol Date: Tue, 25 Jul 2023 14:52:50 +0100 Subject: [PATCH 12/53] fixed linkedlist --- main.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.h b/main.h index e9cce85..f6d189b 100644 --- a/main.h +++ b/main.h @@ -46,8 +46,9 @@ char *check_cmd(char *argv); void execve_cmd(char *cmd, char **argv, char **env); char *_strdup(char *str); /** char *strtok(char *str, char *sep); */ -/** envstruct *insert_end(envstruct *head, char *key, char *value); -char *get_value(envstruct *head, char *key); */ +envstruct *insert_end(envstruct *head, char *key, char *value); +char *get_value(envstruct *head, char *key); +int remove_value(envstruct **head, char *key) typedef void (*sighandler_t)(int); From a4377282486ad9f43602185107be130f119d8d02 Mon Sep 17 00:00:00 2001 From: wrightkhlebisol Date: Tue, 25 Jul 2023 14:54:11 +0100 Subject: [PATCH 13/53] free list --- main.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.h b/main.h index f6d189b..6494f0a 100644 --- a/main.h +++ b/main.h @@ -48,7 +48,8 @@ char *_strdup(char *str); /** char *strtok(char *str, char *sep); */ envstruct *insert_end(envstruct *head, char *key, char *value); char *get_value(envstruct *head, char *key); -int remove_value(envstruct **head, char *key) +int remove_value(envstruct **head, char *key); +void free_list(envstruct *head); typedef void (*sighandler_t)(int); From 39eda653f5917a6829696bf4b7cc93bdd83bc7bd Mon Sep 17 00:00:00 2001 From: wrightkhlebisol Date: Tue, 25 Jul 2023 14:55:40 +0100 Subject: [PATCH 14/53] remove main --- linkedlist.c | 161 +++++++++++++++++++++++++++++---------------------- 1 file changed, 93 insertions(+), 68 deletions(-) diff --git a/linkedlist.c b/linkedlist.c index 68b3e0d..5fd02a1 100644 --- a/linkedlist.c +++ b/linkedlist.c @@ -1,76 +1,101 @@ #include "main.h" -envstruct *insert_end(char *key, char *value) -{ - envstruct *new_node = malloc(sizeof(envstruct)); - - if (new_node == NULL) - return (NULL); - - new_node->key = key; - new_node->value = value; - new_node->next = NULL; - - if (head == NULL) - { - head = new_node; - free(new_node); - return (head); - } - - while (head->next != NULL) - head = head->next; - - head->next = new_node; - free(new_node); - return (head); +envstruct *insert_end(envstruct *head, char *key, char *value) { + envstruct *new_node = malloc(sizeof(envstruct)); + if (new_node == NULL) { + return NULL; + } + + new_node->key = strdup(key); + new_node->value = strdup(value); + new_node->next = NULL; + + if (head == NULL) { + return new_node; + } + + envstruct *curr = head; + while (curr->next != NULL) { + curr = curr->next; + } + curr->next = new_node; + + return head; } -char *get_value(char *key) -{ - envstruct *temp = NULL; - - if (head == NULL) - return (NULL); - - printf("%s 0", head->value); - temp = head; - while (temp != NULL) - { - if (temp->key == key) - return (temp->value); -// printf("%s 1", temp->value); - temp = temp->next; - } - - if (temp->key == key) - return (temp->value); - - return (NULL); +char *get_value(envstruct *head, char *key) { + if (head == NULL || key == NULL) { + return NULL; + } + + envstruct *curr = head; + while (curr != NULL) { + if (strcmp(curr->key, key) == 0) { + return curr->value; + } + curr = curr->next; + } + + return NULL; } -int remove_value(char *key) -{ - envstruct *previous = NULL, *current = NULL, *next_node = NULL; - - if (head == NULL) - return (1); - - if ((head->next == NULL) && (head->key == key)) - { - head = NULL; - return (0); - } - - while (head != NULL) - { - if (head->key == key) - { - previous->next = next_node; - return (0); - } - previous = head; - head = head->next; +int remove_value(envstruct **head, char *key) { + if (head == NULL || *head == NULL) { + return 1; + } + + envstruct *curr = *head; + envstruct *prev = NULL; + + while (curr != NULL) { + if (strcmp(curr->key, key) == 0) { + if (prev == NULL) { + *head = curr->next; + } else { + prev->next = curr->next; + } + free(curr->key); + free(curr->value); + free(curr); + return 0; } - return (1); + + prev = curr; + curr = curr->next; + } + + return 1; +} + +void free_list(envstruct *head) { + while (head != NULL) { + envstruct *temp = head; + head = head->next; + free(temp->key); + free(temp->value); + free(temp); + } +} + +/** +int main(void) { + envstruct *head = NULL; + head = insert_end(head, "name", "caleb"); + head = insert_end(head, "class", "3"); + head = insert_end(head, "age", "121"); + + char *name = get_value(head, "name"); + printf("Name: %s\n", name); + + remove_value(&head, "class"); + printf("After removing 'class':\n"); + name = get_value(head, "class"); + if (name == NULL) { + printf("Class not found.\n"); + } + + free_list(head); + + return 0; } +*/ From bb57b9db3dca57d9aadf09f4d3c3efa79e4889c5 Mon Sep 17 00:00:00 2001 From: wrightkhlebisol Date: Tue, 25 Jul 2023 15:30:59 +0100 Subject: [PATCH 15/53] insert end --- main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index ca6a84c..11ef936 100644 --- a/main.c +++ b/main.c @@ -10,6 +10,7 @@ int main(void) { atexit(clean_up); signal(SIGINT, sig_int_handler); +// envstruct *head = NULL; while (1) { @@ -59,6 +60,7 @@ int main(void) exit(0); } } +// free_list(head); return (0); } @@ -228,7 +230,7 @@ void env_cmd(void) } } -void init_env_list() +void init_env_list(envstruct *head) { while (*environ != NULL) { @@ -237,7 +239,7 @@ void init_env_list() val = strtok(NULL, " "); printf( "%s, %s\n", key, val); //printing each token } - insert_end(key, val); + head = insert_end(head, key, val); *environ++; } From ef632f2495a42e4c7c4bfb63790119984fc79b72 Mon Sep 17 00:00:00 2001 From: wrightkhlebisol Date: Tue, 25 Jul 2023 15:31:43 +0100 Subject: [PATCH 16/53] remove null point for lineptr --- main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.h b/main.h index 6494f0a..8a0c2b9 100644 --- a/main.h +++ b/main.h @@ -26,7 +26,7 @@ typedef struct env_var struct env_var *next; } envstruct; extern char **environ; -char *lineptr = NULL; +char *lineptr; void exit_cmd(int); void env_cmd(void); From 9a16fb2ffdce3296d8e6ce393e617ce508c5fe50 Mon Sep 17 00:00:00 2001 From: Gideon Bature Date: Tue, 25 Jul 2023 15:44:27 +0100 Subject: [PATCH 17/53] resolve merge conflict --- .vscode/settings.json | 12 +- 1a2b3c4d5e6f7g8h9i | 9 + AUTHORS.md | 8 +- README.md | 1822 +++++++++++++++++----------------- linkedlist.c | 62 +- main.c | 724 +++++++------- main.h | 56 ++ test/bin_ls.bash | 86 ++ test/bin_ls_3_times.bash | 88 ++ test/bin_ls_spaces.bash | 89 ++ test/checker.bash | 440 ++++++++ test/checker1.bash | 440 ++++++++ test/checker2.bash | 440 ++++++++ test/checker3.bash | 440 ++++++++ test/checker4.bash | 440 ++++++++ test/empty_input_large.bash | 86 ++ test/empty_input_medium.bash | 86 ++ test/ls_in_current_dir.bash | 90 ++ test/task1/checker1.bash | 880 ++++++++-------- test/task1/checker2.bash | 880 ++++++++-------- test/task1/checker3.bash | 880 ++++++++-------- test/task1/checker4.bash | 880 ++++++++-------- test/task1/checker5.bash | 880 ++++++++-------- test/task1/checker6.bash | 880 ++++++++-------- test/task1/checker7.bash | 880 ++++++++-------- test/task1/checker8.bash | 880 ++++++++-------- test/task1/eight.bash | 172 ++-- test/task1/five.bash | 180 ++-- test/task1/four.bash | 178 ++-- test/task1/one.bash | 172 ++-- test/task1/seven.bash | 172 ++-- test/task1/six.bash | 172 ++-- test/task1/three.bash | 176 ++-- test/task1/two.bash | 172 ++-- test/task2/checker1.bash | 880 ++++++++-------- test/task2/checker2.bash | 880 ++++++++-------- test/task2/checker3.bash | 880 ++++++++-------- test/task2/checker4.bash | 880 ++++++++-------- test/task2/four.bash | 172 ++-- test/task2/one.bash | 172 ++-- test/task2/three.bash | 172 ++-- test/task2/two.bash | 172 ++-- test/task3/checker1.bash | 880 ++++++++-------- test/task3/checker10.bash | 880 ++++++++-------- test/task3/checker11.bash | 880 ++++++++-------- test/task3/checker12.bash | 880 ++++++++-------- test/task3/checker13.bash | 880 ++++++++-------- test/task3/checker14.bash | 880 ++++++++-------- test/task3/checker15.bash | 880 ++++++++-------- test/task3/checker16.bash | 880 ++++++++-------- test/task3/checker17.bash | 880 ++++++++-------- test/task3/checker18.bash | 880 ++++++++-------- test/task3/checker19.bash | 880 ++++++++-------- test/task3/checker2.bash | 880 ++++++++-------- test/task3/checker20.bash | 880 ++++++++-------- test/task3/checker21.bash | 880 ++++++++-------- test/task3/checker22.bash | 880 ++++++++-------- test/task3/checker23.bash | 880 ++++++++-------- test/task3/checker24.bash | 880 ++++++++-------- test/task3/checker25.bash | 880 ++++++++-------- test/task3/checker26.bash | 880 ++++++++-------- test/task3/checker27.bash | 880 ++++++++-------- test/task3/checker28.bash | 880 ++++++++-------- test/task3/checker29.bash | 880 ++++++++-------- test/task3/checker3.bash | 880 ++++++++-------- test/task3/checker30.bash | 880 ++++++++-------- test/task3/checker31.bash | 880 ++++++++-------- test/task3/checker4.bash | 880 ++++++++-------- test/task3/checker5.bash | 880 ++++++++-------- test/task3/checker6.bash | 880 ++++++++-------- test/task3/checker7.bash | 880 ++++++++-------- test/task3/checker8.bash | 880 ++++++++-------- test/task3/checker9.bash | 880 ++++++++-------- test/task3/eight.bash | 180 ++-- test/task3/eighteen.bash | 180 ++-- test/task3/eleven.bash | 172 ++-- test/task3/fifteen.bash | 178 ++-- test/task3/five.bash | 172 ++-- test/task3/four.bash | 172 ++-- test/task3/fourteen.bash | 188 ++-- test/task3/nine.bash | 172 ++-- test/task3/nineteen.bash | 186 ++-- test/task3/one.bash | 172 ++-- test/task3/seven.bash | 180 ++-- test/task3/seventeen.bash | 178 ++-- test/task3/six.bash | 180 ++-- test/task3/sixteen.bash | 182 ++-- test/task3/ten.bash | 182 ++-- test/task3/thirteen.bash | 172 ++-- test/task3/thirty.bash | 186 ++-- test/task3/thirtyone.bash | 186 ++-- test/task3/three.bash | 180 ++-- test/task3/twelve.bash | 182 ++-- test/task3/twenty.bash | 204 ++-- test/task3/twentyeight.bash | 182 ++-- test/task3/twentyfive.bash | 190 ++-- test/task3/twentyfour.bash | 172 ++-- test/task3/twentynine.bash | 188 ++-- test/task3/twentyone.bash | 192 ++-- test/task3/twentyseven.bash | 182 ++-- test/task3/twentysix.bash | 182 ++-- test/task3/twentythree.bash | 176 ++-- test/task3/twentytwo.bash | 192 ++-- test/task3/two.bash | 172 ++-- test/task4/checker1.bash | 880 ++++++++-------- test/task4/checker2.bash | 880 ++++++++-------- test/task4/one.bash | 172 ++-- test/task4/two.bash | 174 ++-- test/task5/checker1.bash | 880 ++++++++-------- test/task5/checker2.bash | 880 ++++++++-------- test/task5/checker3.bash | 880 ++++++++-------- test/task5/one.bash | 230 ++--- test/task5/three.bash | 234 ++--- test/task5/two.bash | 208 ++-- test/usage.md | 30 +- todo.md | 8 +- 116 files changed, 29599 insertions(+), 26809 deletions(-) create mode 100644 1a2b3c4d5e6f7g8h9i create mode 100755 test/bin_ls.bash create mode 100755 test/bin_ls_3_times.bash create mode 100755 test/bin_ls_spaces.bash create mode 100755 test/checker.bash create mode 100755 test/checker1.bash create mode 100755 test/checker2.bash create mode 100755 test/checker3.bash create mode 100755 test/checker4.bash create mode 100755 test/empty_input_large.bash create mode 100755 test/empty_input_medium.bash create mode 100755 test/ls_in_current_dir.bash diff --git a/.vscode/settings.json b/.vscode/settings.json index 54699ff..1ddb59b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,6 @@ -{ - "C_Cpp.errorSquiggles": "disabled", - "files.associations": { - "stdio.h": "c" - } -} +{ + "C_Cpp.errorSquiggles": "disabled", + "files.associations": { + "stdio.h": "c" + } +} diff --git a/1a2b3c4d5e6f7g8h9i b/1a2b3c4d5e6f7g8h9i new file mode 100644 index 0000000..2271a45 --- /dev/null +++ b/1a2b3c4d5e6f7g8h9i @@ -0,0 +1,9 @@ +1a2b3c4d5e6f7g8h9i +AUTHORS.md +README.md +linkedlist.c +main +main.c +main.h +shell +todo.md diff --git a/AUTHORS.md b/AUTHORS.md index 522d4fa..2688796 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -1,4 +1,4 @@ -# This file lists all contributors to the repository. - -Caleb Ogundiya -Gideon Bature +# This file lists all contributors to the repository. + +Caleb Ogundiya +Gideon Bature diff --git a/README.md b/README.md index 8ba5c02..2d2c205 100644 --- a/README.md +++ b/README.md @@ -1,911 +1,911 @@ -# 0x16. C - Simple Shell - -- By: Julien Barbier -- Weight: 10 -- Project to be done in teams of 2 people (your team: Gideon Bature, - Wright OGUNDIYA) -- Project will start Jul 12, 2023 6:00 AM, must end by - Jul 27, 2023 6:00 AM -- Checker will be released at Jul 26, 2023 1:12 AM -- An auto review will be launched at the deadline - - -*For this project, we expect you to look at these concepts:* - -- [Everything you need to know to start coding your own - shell](https://intranet.alxswe.com/concepts/64) -- [Approaching a Project](https://intranet.alxswe.com/concepts/350) - - -## Background Context - -Write a simple UNIX command interpreter. - - - -*^ “The Gates of Shell”, by -Spencer Cheng, featuring -Julien Barbier* - -## Important message from Julien - -It’s time for the famous Simple Shell project. This is one of the most -anticipated project and also one that will challenge you a lot about -everything you have learn so far: - -- Basics of programming -- Basics of C -- Basics of thinking like an engineer -- Group work -- and Learning how to learn - -I would like to take this moment to remind you about a few important -things. - -First, remember the framework. If you do not know it by heart already, -it is probably a good idea to read it again: -https://intranet.alxswe.com/concepts/559 - -Note that there is no point in this framework that says it is ok to look -at code from other people. It is not allowed to look at other people’s -code, either other students or online articles or videos. At ALX SE we -do not copy solutions and we do not look at it when we start a project. - -In the context of learning (some of these will no longer be true when -you work): - -- NEVER copy any code, never look at solution (and never give any - solution to your friends, you are not helping them by doing so) -- ALWAYS write code alone from scratch after you get help to check - that you have actually understood. If you can not do it, you have - not understood enough, and need to study more. Do not rewrite code - from memory, but from understanding. - -I saw some of you sharing resources with each other already. Tutorials -on how to do the shell step by step with all the code associated with -these, or even video and documents with the solution without even any -explanation. This is not the right way to learn. Please do not be -tempted by these links. They will only push you to take shortcuts and / -or cheat. And trust me, you will be caught. -Kimba is not a joke and he is here to -remind you why you are here. - -While we encourage the use of ChatGPT and co in the framework (also, not -right away, but at the right step, see framework), it is important to -understand that the same rules apply to these AI tools (again, in the -context of learning. When you will work it will be completely different, -but context matters). At no point does it say that you are allowed to -use copilot or ChatGPT to code the solution. If you do, you will get -200% (for a few hours), understand 0, learn 0, and you will be caught -for cheating 100%, and then your score for both you and your partner -will be 0%. If you don’t get how to use ChatGPT and other AI tools in -the context of learning, simply do not use them. - -The reality is that at this point of the program, if you have not -cheated before, you have everything you need to complete the project -with what you have learned + the page “Everything you need to know to -start coding your own shell” -https://intranet.alxswe.com/concepts/64 - -Actually, you do not even need to open Google once. Focus on your -whiteboarding, and everything will fall in place. Remember, at ALX SE -you never learn the solution, you learn how to walk toward the solution. -You learn to create the tutorial, so if you follow one, you are looking -at the solution, you are taking a very serious shortcut that will -undermine your learning. - -Last thing about the framework. Note that the first thing to do is “0. -Read”. Every detail counts. Make sure you read and test everything. - -The shell project is a group project. That means you will be paired with -someone. You already did this with printf, so please apply everything -you have learned from the printf experience here. A quick reminder, that -a group project is NOT: - -- I do nothing and cross fingers for my partner to do everything so I - can have a good score -- I do everything because I am so much better than my partner and I - don’t care about them - -A group project at ALX SE is a project that both of you are responsible -for. Everything anyone pushes to Github is the responsibility of both -partners. It is not ok to say later “I didn’t cheat it’s my partner I -didn’t know they didn’t tell me”. - -So you are supposed to work TOGETHER. And you should both understand -every single line of code that any of you pushes. Here is a link for you -to read about pair programming: -https://intranet.alxswe.com/concepts/121 - -If you plan on not working on the shell project (or if at any point in -time you can’t), it is your responsibility to tell both the staff and -your partner so that they can find another partner who will work with -them asap. - -If your group gets caught for plagiarism we will not tolerate “I didn’t -do anything, so I should not be flagged”. Yes you should be flagged, -because you are someone who doesn’t care about others and thought it was -ok to let your partner down and to maybe get the score without doing -anything. - -The shell is an incredibly cool project. GL HF! - -Julien - -## Resources - -**Read or watch**: - -- Unix shell -- Thompson shell -- Ken Thompson -- **Everything you need to know to start coding your own shell** - concept page - -**man or help**: - -- `sh` (*Run `sh` as well*) - -## Learning Objectives - -At the end of this project, you are expected to be able to -explain to anyone, -**without the help of Google**: - -### General - -- Who designed and implemented the original Unix operating system -- Who wrote the first version of the UNIX shell -- Who invented the B programming language (the direct predecessor to - the C programming language) -- Who is Ken Thompson -- How does a shell work -- What is a pid and a ppid -- How to manipulate the environment of the current process -- What is the difference between a function and a system call -- How to create processes -- What are the three prototypes of `main` -- How does the shell use the `PATH` to find the programs -- How to execute another program with the `execve` system call -- How to suspend the execution of a process until one of its children - terminates -- What is `EOF` / “end-of-file”? - -### Copyright - Plagiarism - -- You are tasked to come up with solutions for the tasks below - yourself to meet with the above learning objectives. -- You will not be able to meet the objectives of this or any following - project by copying and pasting someone else’s work. -- You are not allowed to publish any content of this project. -- Any form of plagiarism is strictly forbidden and will result in - removal from the program. - -## Requirements - -### General - -- Allowed editors: `vi`, `vim`, `emacs` -- All your files will be compiled on Ubuntu 20.04 LTS using `gcc`, - using the options `-Wall -Werror -Wextra -pedantic -std=gnu89` -- All your files should end with a new line -- A `README.md` file, at the root of the folder of the project is - mandatory -- Your code should use the `Betty` style. It will be checked using - betty-style.pl and - betty-doc.pl -- Your shell should not have any memory leaks -- No more than 5 functions per file -- All your header files should be include guarded -- Use system calls only when you need to - (why?) -- Write a `README` with the description of your project -- You should have an `AUTHORS` file at the root of your repository, - listing all individuals having contributed content to the - repository. Format, see - Docker - -### GitHub - -\**There should be one project repository per group. If you and your -partner have a repository with the same name in both your accounts, you -risk a 0% score. Add your partner as a collaborator. \** - -## More Info - -### Output - -- Unless specified otherwise, your program **must have the exact same - output** as `sh` (`/bin/sh`) as well as the exact same error output. -- The only difference is when you print an error, the name of the - program must be equivalent to your `argv[0]` (See below) - -Example of error with `sh`: - - $ echo "qwerty" | /bin/sh - /bin/sh: 1: qwerty: not found - $ echo "qwerty" | /bin/../bin/sh - /bin/../bin/sh: 1: qwerty: not found - $ - -Same error with your program `hsh`: - - $ echo "qwerty" | ./hsh - ./hsh: 1: qwerty: not found - $ echo "qwerty" | ./././hsh - ./././hsh: 1: qwerty: not found - $ - -### List of allowed functions and system calls - -- `access` (man 2 access) -- `chdir` (man 2 chdir) -- `close` (man 2 close) -- `closedir` (man 3 closedir) -- `execve` (man 2 execve) -- `exit` (man 3 exit) -- `_exit` (man 2 \_exit) -- `fflush` (man 3 fflush) -- `fork` (man 2 fork) -- `free` (man 3 free) -- `getcwd` (man 3 getcwd) -- `getline` (man 3 getline) -- `getpid` (man 2 getpid) -- `isatty` (man 3 isatty) -- `kill` (man 2 kill) -- `malloc` (man 3 malloc) -- `open` (man 2 open) -- `opendir` (man 3 opendir) -- `perror` (man 3 perror) -- `read` (man 2 read) -- `readdir` (man 3 readdir) -- `signal` (man 2 signal) -- `stat` (\_\_xstat) (man 2 stat) -- `lstat` (\_\_lxstat) (man 2 lstat) -- `fstat` (\_\_fxstat) (man 2 fstat) -- `strtok` (man 3 strtok) -- `wait` (man 2 wait) -- `waitpid` (man 2 waitpid) -- `wait3` (man 2 wait3) -- `wait4` (man 2 wait4) -- `write` (man 2 write) - -### Compilation - -Your shell will be compiled this way: - - gcc -Wall -Werror -Wextra -pedantic -std=gnu89 *.c -o hsh - -### Testing - -Your shell should work like this in interactive mode: - - $ ./hsh - ($) /bin/ls - hsh main.c shell.c - ($) - ($) exit - $ - -But also in non-interactive mode: - - $ echo "/bin/ls" | ./hsh - hsh main.c shell.c test_ls_2 - $ - $ cat test_ls_2 - /bin/ls - /bin/ls - $ - $ cat test_ls_2 | ./hsh - hsh main.c shell.c test_ls_2 - hsh main.c shell.c test_ls_2 - $ - -### Checks - -The Checker will be released at the end of the project (1-2 days before -the deadline). We **strongly** encourage the entire class to work -together to create a suite of checks covering both regular tests and -edge cases for each task. See task `8. Test suite`. - - - - - -## Tasks - -Write a beautiful code that passes the Betty checks - - - -
- -
- -**Repo:** - -- GitHub repository: `simple_shell` - -Help - -#### Learners who are done with "0. Betty would be proud" - -Get a sandbox - -### 1. Simple shell 0.1 - -Write a UNIX command line interpreter. - -- Usage: `simple_shell` - -Your Shell should: - -- Display a prompt and wait for the user to type a command. A command - line always ends with a new line. -- The prompt is displayed again each time a command has been executed. -- The command lines are simple, no semicolons, no pipes, no - redirections or any other advanced features. -- The command lines are made only of one word. No arguments will be - passed to programs. -- If an executable cannot be found, print an error message and display - the prompt again. -- Handle errors. -- You have to handle the “end of file” condition (`Ctrl+D`) - -You don’t have to: - -- use the `PATH` -- implement built-ins -- handle special characters : `"`, `'`, `` ` ``, `\`, `*`, `&`, `#` -- be able to move the cursor -- handle commands with arguments - -*`execve` will be the core part of your Shell, don’t forget to pass the -environ to it…* - - julien@ubuntu:~/shell$ ./shell - #cisfun$ ls - ./shell: No such file or directory - #cisfun$ /bin/ls - barbie_j env-main.c exec.c fork.c pid.c ppid.c prompt prompt.c shell.c stat.c wait - env-environ.c exec fork mypid ppid printenv promptc shell stat test_scripting.sh wait.c - #cisfun$ /bin/ls -l - ./shell: No such file or directory - #cisfun$ ^[[D^[[D^[[D - ./shell: No such file or directory - #cisfun$ ^[[C^[[C^[[C^[[C - ./shell: No such file or directory - #cisfun$ exit - ./shell: No such file or directory - #cisfun$ ^C - julien@ubuntu:~/shell$ echo "/bin/ls" | ./shell - barbie_j env-main.c exec.c fork.c pid.c ppid.c prompt prompt.c shell.c stat.c wait - env-environ.c exec fork mypid ppid printenv promptc shell stat test_scripting.sh wait.c - #cisfun$ julien@ubuntu:~/shell$ - -**Repo:** - -- GitHub repository: `simple_shell` - -Help - - -#### Learners who are done with "1. Simple shell 0.1" - -Get a sandbox - -### 2. Simple shell 0.2 - -Simple shell 0.1 + - -- Handle command lines with arguments - -**Repo:** - -- GitHub repository: `simple_shell` - -Help - -#### Learners who are done with "2. Simple shell 0.2" - -Get a sandbox - -### 3. Simple shell 0.3 - -Simple shell 0.2 + - -- Handle the `PATH` -- `fork` must not be called if the command doesn’t exist - - - - julien@ubuntu:~/shell$ ./shell_0.3 - :) /bin/ls - barbie_j env-main.c exec.c fork.c pid.c ppid.c prompt prompt.c shell_0.3 stat test_scripting.sh wait.c - env-environ.c exec fork mypid ppid printenv promptc shell shell.c stat.c wait - :) ls - barbie_j env-main.c exec.c fork.c pid.c ppid.c prompt prompt.c shell_0.3 stat test_scripting.sh wait.c - env-environ.c exec fork mypid ppid printenv promptc shell shell.c stat.c wait - :) ls -l /tmp - total 20 - -rw------- 1 julien julien 0 Dec 5 12:09 config-err-aAMZrR - drwx------ 3 root root 4096 Dec 5 12:09 systemd-private-062a0eca7f2a44349733e78cb4abdff4-colord.service-V7DUzr - drwx------ 3 root root 4096 Dec 5 12:09 systemd-private-062a0eca7f2a44349733e78cb4abdff4-rtkit-daemon.service-ANGvoV - drwx------ 3 root root 4096 Dec 5 12:07 systemd-private-062a0eca7f2a44349733e78cb4abdff4-systemd-timesyncd.service-CdXUtH - -rw-rw-r-- 1 julien julien 0 Dec 5 12:09 unity_support_test.0 - :) ^C - julien@ubuntu:~/shell$ - - -**Repo:** - -- GitHub repository: `simple_shell` - -Help - -#### Learners who are done with "3. Simple shell 0.3" - -Get a sandbox - -### 4. Simple shell 0.4 - -Simple shell 0.3 + - -- Implement the `exit` built-in, that exits the shell -- Usage: `exit` -- You don’t have to handle any argument to the built-in `exit` - - -**Repo:** - -- GitHub repository: `simple_shell` - -Help - -#### Learners who are done with "4. Simple shell 0.4" - -Get a sandbox - -### 5. Simple shell 1.0 - -Simple shell 0.4 + - -- Implement the `env` **built-in**, that prints the current - environment - - - - julien@ubuntu:~/shell$ ./simple_shell - $ env - USER=julien - LANGUAGE=en_US - SESSION=ubuntu - COMPIZ_CONFIG_PROFILE=ubuntu - SHLVL=1 - HOME=/home/julien - C_IS=Fun_:) - DESKTOP_SESSION=ubuntu - LOGNAME=julien - TERM=xterm-256color - PATH=/home/julien/bin:/home/julien/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin - DISPLAY=:0 - $ exit - julien@ubuntu:~/shell$ - - -**Repo:** - -- GitHub repository: `simple_shell` - -Help - - -#### Learners who are done with "5. Simple shell 1.0" - -Get a sandbox - -### 6. Simple shell 0.1.1 - -Simple shell 0.1 + - -- Write your own `getline` function -- Use a buffer to read many chars at once and call the least possible - the `read` system call -- You will need to use `static` variables -- You are not allowed to use `getline` - -You don’t have to: - -- be able to move the cursor - -Help - -#### Learners who are done with "6. Simple shell 0.1.1" - -Get a sandbox - -### 7. Simple shell 0.2.1 - -Simple shell 0.2 + - -- You are not allowed to use `strtok` - -**Repo:** - -- GitHub repository: `simple_shell` - -Help - -#### Learners who are done with "7. Simple shell 0.2.1" - -Get a sandbox - -### 8. Simple shell 0.4.1 - -Simple shell 0.4 + - -- handle arguments for the built-in `exit` -- Usage: `exit status`, where `status` is an integer used to exit the - shell - - - - julien@ubuntu:~/shell$ ./shell_0.4.1 - $ exit 98 - julien@ubuntu:~/shell$ echo $? - 98 - julien@ubuntu:~/shell$ - -**Repo:** - -- GitHub repository: `simple_shell` - -Help - -#### Learners who are done with "8. Simple shell 0.4.1" - -Get a sandbox - -### 9. setenv, unsetenv - -Simple shell 1.0 + - -Implement the `setenv` and `unsetenv` builtin commands - -- `setenv` - - Initialize a new environment variable, or modify an existing one - - Command syntax: `setenv VARIABLE VALUE` - - Should print something on stderr on failure -- `unsetenv` - - Remove an environment variable - - Command syntax: `unsetenv VARIABLE` - - Should print something on stderr on failure - -**Repo:** - -- GitHub repository: `simple_shell` - -Help - -#### Learners who are done with "9. setenv, unsetenv" - -Get a sandbox - -### 10. cd - -Simple shell 1.0 + - -Implement the builtin command `cd`: - -- Changes the current directory of the process. -- Command syntax: `cd [DIRECTORY]` -- If no argument is given to `cd` the command must be interpreted like - `cd $HOME` -- You have to handle the command `cd -` -- You have to update the environment variable `PWD` when you change - directory - -`man chdir`, `man getcwd` - -**Repo:** - -- GitHub repository: `simple_shell` - -Help - -#### Learners who are done with "10. cd" - -Get a sandbox - -### 11. ; - -Simple shell 1.0 + - -- Handle the commands separator `;` - - - - alex@~$ ls /var ; ls /var - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ ls /hbtn ; ls /var - ls: cannot access /hbtn: No such file or directory - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ ls /var ; ls /hbtn - backups cache crash lib local lock log mail metrics opt run spool tmp - ls: cannot access /hbtn: No such file or directory - alex@~$ ls /var ; ls /hbtn ; ls /var ; ls /var - backups cache crash lib local lock log mail metrics opt run spool tmp - ls: cannot access /hbtn: No such file or directory - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ - -**Repo:** - -- GitHub repository: `simple_shell` - -Help - -#### Learners who are done with "11. ;" - -Get a sandbox - -### 12. && and \|\| - -Simple shell 1.0 + - -- Handle the `&&` and `||` shell logical operators - - - - alex@~$ ls /var && ls /var - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ ls /hbtn && ls /var - ls: cannot access /hbtn: No such file or directory - alex@~$ ls /var && ls /var && ls /var && ls /hbtn - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - ls: cannot access /hbtn: No such file or directory - alex@~$ ls /var && ls /var && ls /var && ls /hbtn && ls /hbtn - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - ls: cannot access /hbtn: No such file or directory - alex@~$ - alex@~$ ls /var || ls /var - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ ls /hbtn || ls /var - ls: cannot access /hbtn: No such file or directory - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ ls /hbtn || ls /hbtn || ls /hbtn || ls /var - ls: cannot access /hbtn: No such file or directory - ls: cannot access /hbtn: No such file or directory - ls: cannot access /hbtn: No such file or directory - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ ls /hbtn || ls /hbtn || ls /hbtn || ls /var || ls /var - ls: cannot access /hbtn: No such file or directory - ls: cannot access /hbtn: No such file or directory - ls: cannot access /hbtn: No such file or directory - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ - -**Repo:** - -- GitHub repository: `simple_shell` - -Help - -#### Learners who are done with "12. && and \|\|" - -Get a sandbox - -### 13. alias - -Simple shell 1.0 + - -- Implement the `alias` builtin command -- Usage: `alias [name[='value'] ...]` - - `alias`: Prints a list of all aliases, one per line, in the form - `name='value'` - - `alias name [name2 ...]`: Prints the aliases `name`, `name2`, - etc 1 per line, in the form `name='value'` - - `alias name='value' [...]`: Defines an alias for each `name` - whose `value` is given. If `name` is already an alias, replaces - its value with `value` - -**Repo:** - -- GitHub repository: `simple_shell` - -Help - -#### Learners who are done with "13. alias" - -Get a sandbox - -### 14. Variables - -Simple shell 1.0 + - -- Handle variables replacement -- Handle the `$?` variable -- Handle the `$$` variable - - - - julien@ubuntu:~/shell$ ./hsh - $ ls /var - backups cache crash lib local lock log mail metrics opt run snap spool tmp - $ echo $? - 0 - $ echo $$ - 5104 - $ echo $PATH - /home/julien/bin:/home/julien/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin - $ exit - julien@ubuntu:~/shell$ - -Help - -#### Learners who are done with "14. Variables" - -Get a sandbox - -### 15. Comments - -Simple shell 1.0 + - -- Handle comments (`#`) - - - - julien@ubuntu:~/shell$ sh - $ echo $$ # ls -la - 5114 - $ exit - julien@ubuntu:~/shell$ - - -Help - -#### Learners who are done with "15. Comments" - -Get a sandbox - -### 16. File as input - -Simple shell 1.0 + - -- Usage: `simple_shell [filename]` -- Your shell can take a file as a command line argument -- The file contains all the commands that your shell should run before - exiting -- The file should contain one command per line -- In this mode, the shell should not print a prompt and should not - read from `stdin` - - -**Repo:** - -- GitHub repository: `simple_shell` - -Help - -#### Learners who are done with "16. File as input" - -Get a sandbox - -#### Recommended Sandbox - -### 1 image(1/2 Sandboxes spawned) - - -### Ubuntu 20.04Asleep - - -Basic Ubuntu 20.04, with vim, emacs, curl, wget and all needed for -Foundations - -Copyright © 2023 ALX, All rights reserved. - -#### Markdown Guide - -
- - + +
+ +## Tasks + +Write a beautiful code that passes the Betty checks + + + +
+ +
+ +**Repo:** + +- GitHub repository: `simple_shell` + +Help + +#### Learners who are done with "0. Betty would be proud" + +Get a sandbox + +### 1. Simple shell 0.1 + +Write a UNIX command line interpreter. + +- Usage: `simple_shell` + +Your Shell should: + +- Display a prompt and wait for the user to type a command. A command + line always ends with a new line. +- The prompt is displayed again each time a command has been executed. +- The command lines are simple, no semicolons, no pipes, no + redirections or any other advanced features. +- The command lines are made only of one word. No arguments will be + passed to programs. +- If an executable cannot be found, print an error message and display + the prompt again. +- Handle errors. +- You have to handle the “end of file” condition (`Ctrl+D`) + +You don’t have to: + +- use the `PATH` +- implement built-ins +- handle special characters : `"`, `'`, `` ` ``, `\`, `*`, `&`, `#` +- be able to move the cursor +- handle commands with arguments + +*`execve` will be the core part of your Shell, don’t forget to pass the +environ to it…* + + julien@ubuntu:~/shell$ ./shell + #cisfun$ ls + ./shell: No such file or directory + #cisfun$ /bin/ls + barbie_j env-main.c exec.c fork.c pid.c ppid.c prompt prompt.c shell.c stat.c wait + env-environ.c exec fork mypid ppid printenv promptc shell stat test_scripting.sh wait.c + #cisfun$ /bin/ls -l + ./shell: No such file or directory + #cisfun$ ^[[D^[[D^[[D + ./shell: No such file or directory + #cisfun$ ^[[C^[[C^[[C^[[C + ./shell: No such file or directory + #cisfun$ exit + ./shell: No such file or directory + #cisfun$ ^C + julien@ubuntu:~/shell$ echo "/bin/ls" | ./shell + barbie_j env-main.c exec.c fork.c pid.c ppid.c prompt prompt.c shell.c stat.c wait + env-environ.c exec fork mypid ppid printenv promptc shell stat test_scripting.sh wait.c + #cisfun$ julien@ubuntu:~/shell$ + +**Repo:** + +- GitHub repository: `simple_shell` + +Help + + +#### Learners who are done with "1. Simple shell 0.1" + +Get a sandbox + +### 2. Simple shell 0.2 + +Simple shell 0.1 + + +- Handle command lines with arguments + +**Repo:** + +- GitHub repository: `simple_shell` + +Help + +#### Learners who are done with "2. Simple shell 0.2" + +Get a sandbox + +### 3. Simple shell 0.3 + +Simple shell 0.2 + + +- Handle the `PATH` +- `fork` must not be called if the command doesn’t exist + + + + julien@ubuntu:~/shell$ ./shell_0.3 + :) /bin/ls + barbie_j env-main.c exec.c fork.c pid.c ppid.c prompt prompt.c shell_0.3 stat test_scripting.sh wait.c + env-environ.c exec fork mypid ppid printenv promptc shell shell.c stat.c wait + :) ls + barbie_j env-main.c exec.c fork.c pid.c ppid.c prompt prompt.c shell_0.3 stat test_scripting.sh wait.c + env-environ.c exec fork mypid ppid printenv promptc shell shell.c stat.c wait + :) ls -l /tmp + total 20 + -rw------- 1 julien julien 0 Dec 5 12:09 config-err-aAMZrR + drwx------ 3 root root 4096 Dec 5 12:09 systemd-private-062a0eca7f2a44349733e78cb4abdff4-colord.service-V7DUzr + drwx------ 3 root root 4096 Dec 5 12:09 systemd-private-062a0eca7f2a44349733e78cb4abdff4-rtkit-daemon.service-ANGvoV + drwx------ 3 root root 4096 Dec 5 12:07 systemd-private-062a0eca7f2a44349733e78cb4abdff4-systemd-timesyncd.service-CdXUtH + -rw-rw-r-- 1 julien julien 0 Dec 5 12:09 unity_support_test.0 + :) ^C + julien@ubuntu:~/shell$ + + +**Repo:** + +- GitHub repository: `simple_shell` + +Help + +#### Learners who are done with "3. Simple shell 0.3" + +Get a sandbox + +### 4. Simple shell 0.4 + +Simple shell 0.3 + + +- Implement the `exit` built-in, that exits the shell +- Usage: `exit` +- You don’t have to handle any argument to the built-in `exit` + + +**Repo:** + +- GitHub repository: `simple_shell` + +Help + +#### Learners who are done with "4. Simple shell 0.4" + +Get a sandbox + +### 5. Simple shell 1.0 + +Simple shell 0.4 + + +- Implement the `env` **built-in**, that prints the current + environment + + + + julien@ubuntu:~/shell$ ./simple_shell + $ env + USER=julien + LANGUAGE=en_US + SESSION=ubuntu + COMPIZ_CONFIG_PROFILE=ubuntu + SHLVL=1 + HOME=/home/julien + C_IS=Fun_:) + DESKTOP_SESSION=ubuntu + LOGNAME=julien + TERM=xterm-256color + PATH=/home/julien/bin:/home/julien/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin + DISPLAY=:0 + $ exit + julien@ubuntu:~/shell$ + + +**Repo:** + +- GitHub repository: `simple_shell` + +Help + + +#### Learners who are done with "5. Simple shell 1.0" + +Get a sandbox + +### 6. Simple shell 0.1.1 + +Simple shell 0.1 + + +- Write your own `getline` function +- Use a buffer to read many chars at once and call the least possible + the `read` system call +- You will need to use `static` variables +- You are not allowed to use `getline` + +You don’t have to: + +- be able to move the cursor + +Help + +#### Learners who are done with "6. Simple shell 0.1.1" + +Get a sandbox + +### 7. Simple shell 0.2.1 + +Simple shell 0.2 + + +- You are not allowed to use `strtok` + +**Repo:** + +- GitHub repository: `simple_shell` + +Help + +#### Learners who are done with "7. Simple shell 0.2.1" + +Get a sandbox + +### 8. Simple shell 0.4.1 + +Simple shell 0.4 + + +- handle arguments for the built-in `exit` +- Usage: `exit status`, where `status` is an integer used to exit the + shell + + + + julien@ubuntu:~/shell$ ./shell_0.4.1 + $ exit 98 + julien@ubuntu:~/shell$ echo $? + 98 + julien@ubuntu:~/shell$ + +**Repo:** + +- GitHub repository: `simple_shell` + +Help + +#### Learners who are done with "8. Simple shell 0.4.1" + +Get a sandbox + +### 9. setenv, unsetenv + +Simple shell 1.0 + + +Implement the `setenv` and `unsetenv` builtin commands + +- `setenv` + - Initialize a new environment variable, or modify an existing one + - Command syntax: `setenv VARIABLE VALUE` + - Should print something on stderr on failure +- `unsetenv` + - Remove an environment variable + - Command syntax: `unsetenv VARIABLE` + - Should print something on stderr on failure + +**Repo:** + +- GitHub repository: `simple_shell` + +Help + +#### Learners who are done with "9. setenv, unsetenv" + +Get a sandbox + +### 10. cd + +Simple shell 1.0 + + +Implement the builtin command `cd`: + +- Changes the current directory of the process. +- Command syntax: `cd [DIRECTORY]` +- If no argument is given to `cd` the command must be interpreted like + `cd $HOME` +- You have to handle the command `cd -` +- You have to update the environment variable `PWD` when you change + directory + +`man chdir`, `man getcwd` + +**Repo:** + +- GitHub repository: `simple_shell` + +Help + +#### Learners who are done with "10. cd" + +Get a sandbox + +### 11. ; + +Simple shell 1.0 + + +- Handle the commands separator `;` + + + + alex@~$ ls /var ; ls /var + backups cache crash lib local lock log mail metrics opt run spool tmp + backups cache crash lib local lock log mail metrics opt run spool tmp + alex@~$ ls /hbtn ; ls /var + ls: cannot access /hbtn: No such file or directory + backups cache crash lib local lock log mail metrics opt run spool tmp + alex@~$ ls /var ; ls /hbtn + backups cache crash lib local lock log mail metrics opt run spool tmp + ls: cannot access /hbtn: No such file or directory + alex@~$ ls /var ; ls /hbtn ; ls /var ; ls /var + backups cache crash lib local lock log mail metrics opt run spool tmp + ls: cannot access /hbtn: No such file or directory + backups cache crash lib local lock log mail metrics opt run spool tmp + backups cache crash lib local lock log mail metrics opt run spool tmp + alex@~$ + +**Repo:** + +- GitHub repository: `simple_shell` + +Help + +#### Learners who are done with "11. ;" + +Get a sandbox + +### 12. && and \|\| + +Simple shell 1.0 + + +- Handle the `&&` and `||` shell logical operators + + + + alex@~$ ls /var && ls /var + backups cache crash lib local lock log mail metrics opt run spool tmp + backups cache crash lib local lock log mail metrics opt run spool tmp + alex@~$ ls /hbtn && ls /var + ls: cannot access /hbtn: No such file or directory + alex@~$ ls /var && ls /var && ls /var && ls /hbtn + backups cache crash lib local lock log mail metrics opt run spool tmp + backups cache crash lib local lock log mail metrics opt run spool tmp + backups cache crash lib local lock log mail metrics opt run spool tmp + ls: cannot access /hbtn: No such file or directory + alex@~$ ls /var && ls /var && ls /var && ls /hbtn && ls /hbtn + backups cache crash lib local lock log mail metrics opt run spool tmp + backups cache crash lib local lock log mail metrics opt run spool tmp + backups cache crash lib local lock log mail metrics opt run spool tmp + ls: cannot access /hbtn: No such file or directory + alex@~$ + alex@~$ ls /var || ls /var + backups cache crash lib local lock log mail metrics opt run spool tmp + alex@~$ ls /hbtn || ls /var + ls: cannot access /hbtn: No such file or directory + backups cache crash lib local lock log mail metrics opt run spool tmp + alex@~$ ls /hbtn || ls /hbtn || ls /hbtn || ls /var + ls: cannot access /hbtn: No such file or directory + ls: cannot access /hbtn: No such file or directory + ls: cannot access /hbtn: No such file or directory + backups cache crash lib local lock log mail metrics opt run spool tmp + alex@~$ ls /hbtn || ls /hbtn || ls /hbtn || ls /var || ls /var + ls: cannot access /hbtn: No such file or directory + ls: cannot access /hbtn: No such file or directory + ls: cannot access /hbtn: No such file or directory + backups cache crash lib local lock log mail metrics opt run spool tmp + alex@~$ + +**Repo:** + +- GitHub repository: `simple_shell` + +Help + +#### Learners who are done with "12. && and \|\|" + +Get a sandbox + +### 13. alias + +Simple shell 1.0 + + +- Implement the `alias` builtin command +- Usage: `alias [name[='value'] ...]` + - `alias`: Prints a list of all aliases, one per line, in the form + `name='value'` + - `alias name [name2 ...]`: Prints the aliases `name`, `name2`, + etc 1 per line, in the form `name='value'` + - `alias name='value' [...]`: Defines an alias for each `name` + whose `value` is given. If `name` is already an alias, replaces + its value with `value` + +**Repo:** + +- GitHub repository: `simple_shell` + +Help + +#### Learners who are done with "13. alias" + +Get a sandbox + +### 14. Variables + +Simple shell 1.0 + + +- Handle variables replacement +- Handle the `$?` variable +- Handle the `$$` variable + + + + julien@ubuntu:~/shell$ ./hsh + $ ls /var + backups cache crash lib local lock log mail metrics opt run snap spool tmp + $ echo $? + 0 + $ echo $$ + 5104 + $ echo $PATH + /home/julien/bin:/home/julien/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin + $ exit + julien@ubuntu:~/shell$ + +Help + +#### Learners who are done with "14. Variables" + +Get a sandbox + +### 15. Comments + +Simple shell 1.0 + + +- Handle comments (`#`) + + + + julien@ubuntu:~/shell$ sh + $ echo $$ # ls -la + 5114 + $ exit + julien@ubuntu:~/shell$ + + +Help + +#### Learners who are done with "15. Comments" + +Get a sandbox + +### 16. File as input + +Simple shell 1.0 + + +- Usage: `simple_shell [filename]` +- Your shell can take a file as a command line argument +- The file contains all the commands that your shell should run before + exiting +- The file should contain one command per line +- In this mode, the shell should not print a prompt and should not + read from `stdin` + + +**Repo:** + +- GitHub repository: `simple_shell` + +Help + +#### Learners who are done with "16. File as input" + +Get a sandbox + +#### Recommended Sandbox + +### 1 image(1/2 Sandboxes spawned) + + +### Ubuntu 20.04Asleep + + +Basic Ubuntu 20.04, with vim, emacs, curl, wget and all needed for +Foundations + +Copyright © 2023 ALX, All rights reserved. + +#### Markdown Guide + +
+ + +
- + ## Tasks -Write a beautiful code that passes the Betty checks + Write a beautiful code that passes the Betty checks - + -
+
-
+
-**Repo:** + **Repo:** -- GitHub repository: `simple_shell` + - GitHub repository: `simple_shell` -Help + Help #### Learners who are done with "0. Betty would be proud" -Get a sandbox + Get a sandbox ### 1. Simple shell 0.1 -Write a UNIX command line interpreter. + Write a UNIX command line interpreter. -- Usage: `simple_shell` + - Usage: `simple_shell` -Your Shell should: + Your Shell should: -- Display a prompt and wait for the user to type a command. A command - line always ends with a new line. -- The prompt is displayed again each time a command has been executed. -- The command lines are simple, no semicolons, no pipes, no - redirections or any other advanced features. -- The command lines are made only of one word. No arguments will be - passed to programs. -- If an executable cannot be found, print an error message and display - the prompt again. -- Handle errors. + - Display a prompt and wait for the user to type a command. A command + line always ends with a new line. + - The prompt is displayed again each time a command has been executed. + - The command lines are simple, no semicolons, no pipes, no + redirections or any other advanced features. + - The command lines are made only of one word. No arguments will be + passed to programs. + - If an executable cannot be found, print an error message and display + the prompt again. + - Handle errors. - You have to handle the “end of file” condition (`Ctrl+D`) -You don’t have to: + You don’t have to: -- use the `PATH` -- implement built-ins -- handle special characters : `"`, `'`, `` ` ``, `\`, `*`, `&`, `#` -- be able to move the cursor -- handle commands with arguments + - use the `PATH` + - implement built-ins + - handle special characters : `"`, `'`, `` ` ``, `\`, `*`, `&`, `#` + - be able to move the cursor + - handle commands with arguments -*`execve` will be the core part of your Shell, don’t forget to pass the -environ to it…* + *`execve` will be the core part of your Shell, don’t forget to pass the + environ to it…* - julien@ubuntu:~/shell$ ./shell - #cisfun$ ls - ./shell: No such file or directory - #cisfun$ /bin/ls - barbie_j env-main.c exec.c fork.c pid.c ppid.c prompt prompt.c shell.c stat.c wait - env-environ.c exec fork mypid ppid printenv promptc shell stat test_scripting.sh wait.c - #cisfun$ /bin/ls -l - ./shell: No such file or directory - #cisfun$ ^[[D^[[D^[[D - ./shell: No such file or directory - #cisfun$ ^[[C^[[C^[[C^[[C - ./shell: No such file or directory - #cisfun$ exit - ./shell: No such file or directory - #cisfun$ ^C - julien@ubuntu:~/shell$ echo "/bin/ls" | ./shell - barbie_j env-main.c exec.c fork.c pid.c ppid.c prompt prompt.c shell.c stat.c wait - env-environ.c exec fork mypid ppid printenv promptc shell stat test_scripting.sh wait.c - #cisfun$ julien@ubuntu:~/shell$ + julien@ubuntu:~/shell$ ./shell +#cisfun$ ls + ./shell: No such file or directory +#cisfun$ /bin/ls + barbie_j env-main.c exec.c fork.c pid.c ppid.c prompt prompt.c shell.c stat.c wait + env-environ.c exec fork mypid ppid printenv promptc shell stat test_scripting.sh wait.c +#cisfun$ /bin/ls -l + ./shell: No such file or directory +#cisfun$ ^[[D^[[D^[[D + ./shell: No such file or directory +#cisfun$ ^[[C^[[C^[[C^[[C + ./shell: No such file or directory +#cisfun$ exit + ./shell: No such file or directory +#cisfun$ ^C + julien@ubuntu:~/shell$ echo "/bin/ls" | ./shell + barbie_j env-main.c exec.c fork.c pid.c ppid.c prompt prompt.c shell.c stat.c wait + env-environ.c exec fork mypid ppid printenv promptc shell stat test_scripting.sh wait.c +#cisfun$ julien@ubuntu:~/shell$ -**Repo:** + **Repo:** -- GitHub repository: `simple_shell` + - GitHub repository: `simple_shell` -Help + Help #### Learners who are done with "1. Simple shell 0.1" -Get a sandbox + Get a sandbox ### 2. Simple shell 0.2 -Simple shell 0.1 + + Simple shell 0.1 + -- Handle command lines with arguments + - Handle command lines with arguments -**Repo:** + **Repo:** -- GitHub repository: `simple_shell` + - GitHub repository: `simple_shell` -Help + Help #### Learners who are done with "2. Simple shell 0.2" -Get a sandbox + Get a sandbox ### 3. Simple shell 0.3 -Simple shell 0.2 + + Simple shell 0.2 + -- Handle the `PATH` -- `fork` must not be called if the command doesn’t exist + - Handle the `PATH` + - `fork` must not be called if the command doesn’t exist - + - julien@ubuntu:~/shell$ ./shell_0.3 - :) /bin/ls - barbie_j env-main.c exec.c fork.c pid.c ppid.c prompt prompt.c shell_0.3 stat test_scripting.sh wait.c - env-environ.c exec fork mypid ppid printenv promptc shell shell.c stat.c wait - :) ls - barbie_j env-main.c exec.c fork.c pid.c ppid.c prompt prompt.c shell_0.3 stat test_scripting.sh wait.c - env-environ.c exec fork mypid ppid printenv promptc shell shell.c stat.c wait - :) ls -l /tmp - total 20 - -rw------- 1 julien julien 0 Dec 5 12:09 config-err-aAMZrR - drwx------ 3 root root 4096 Dec 5 12:09 systemd-private-062a0eca7f2a44349733e78cb4abdff4-colord.service-V7DUzr - drwx------ 3 root root 4096 Dec 5 12:09 systemd-private-062a0eca7f2a44349733e78cb4abdff4-rtkit-daemon.service-ANGvoV - drwx------ 3 root root 4096 Dec 5 12:07 systemd-private-062a0eca7f2a44349733e78cb4abdff4-systemd-timesyncd.service-CdXUtH - -rw-rw-r-- 1 julien julien 0 Dec 5 12:09 unity_support_test.0 - :) ^C - julien@ubuntu:~/shell$ + julien@ubuntu:~/shell$ ./shell_0.3 + :) /bin/ls + barbie_j env-main.c exec.c fork.c pid.c ppid.c prompt prompt.c shell_0.3 stat test_scripting.sh wait.c + env-environ.c exec fork mypid ppid printenv promptc shell shell.c stat.c wait + :) ls + barbie_j env-main.c exec.c fork.c pid.c ppid.c prompt prompt.c shell_0.3 stat test_scripting.sh wait.c + env-environ.c exec fork mypid ppid printenv promptc shell shell.c stat.c wait + :) ls -l /tmp + total 20 + -rw------- 1 julien julien 0 Dec 5 12:09 config-err-aAMZrR + drwx------ 3 root root 4096 Dec 5 12:09 systemd-private-062a0eca7f2a44349733e78cb4abdff4-colord.service-V7DUzr + drwx------ 3 root root 4096 Dec 5 12:09 systemd-private-062a0eca7f2a44349733e78cb4abdff4-rtkit-daemon.service-ANGvoV + drwx------ 3 root root 4096 Dec 5 12:07 systemd-private-062a0eca7f2a44349733e78cb4abdff4-systemd-timesyncd.service-CdXUtH + -rw-rw-r-- 1 julien julien 0 Dec 5 12:09 unity_support_test.0 + :) ^C + julien@ubuntu:~/shell$ -**Repo:** + **Repo:** -- GitHub repository: `simple_shell` + - GitHub repository: `simple_shell` -Help + Help #### Learners who are done with "3. Simple shell 0.3" -Get a sandbox + Get a sandbox ### 4. Simple shell 0.4 -Simple shell 0.3 + + Simple shell 0.3 + -- Implement the `exit` built-in, that exits the shell -- Usage: `exit` -- You don’t have to handle any argument to the built-in `exit` + - Implement the `exit` built-in, that exits the shell + - Usage: `exit` + - You don’t have to handle any argument to the built-in `exit` -**Repo:** + **Repo:** -- GitHub repository: `simple_shell` + - GitHub repository: `simple_shell` -Help + Help #### Learners who are done with "4. Simple shell 0.4" -Get a sandbox + Get a sandbox ### 5. Simple shell 1.0 -Simple shell 0.4 + + Simple shell 0.4 + -- Implement the `env` **built-in**, that prints the current - environment + - Implement the `env` **built-in**, that prints the current + environment - + - julien@ubuntu:~/shell$ ./simple_shell - $ env - USER=julien - LANGUAGE=en_US - SESSION=ubuntu - COMPIZ_CONFIG_PROFILE=ubuntu - SHLVL=1 - HOME=/home/julien - C_IS=Fun_:) - DESKTOP_SESSION=ubuntu - LOGNAME=julien - TERM=xterm-256color - PATH=/home/julien/bin:/home/julien/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin - DISPLAY=:0 - $ exit - julien@ubuntu:~/shell$ + julien@ubuntu:~/shell$ ./simple_shell + $ env + USER=julien + LANGUAGE=en_US + SESSION=ubuntu + COMPIZ_CONFIG_PROFILE=ubuntu + SHLVL=1 + HOME=/home/julien + C_IS=Fun_:) + DESKTOP_SESSION=ubuntu + LOGNAME=julien + TERM=xterm-256color + PATH=/home/julien/bin:/home/julien/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin + DISPLAY=:0 + $ exit + julien@ubuntu:~/shell$ -**Repo:** + **Repo:** -- GitHub repository: `simple_shell` + - GitHub repository: `simple_shell` -Help + Help #### Learners who are done with "5. Simple shell 1.0" -Get a sandbox + Get a sandbox ### 6. Simple shell 0.1.1 -Simple shell 0.1 + + Simple shell 0.1 + -- Write your own `getline` function -- Use a buffer to read many chars at once and call the least possible - the `read` system call -- You will need to use `static` variables -- You are not allowed to use `getline` + - Write your own `getline` function + - Use a buffer to read many chars at once and call the least possible + the `read` system call + - You will need to use `static` variables + - You are not allowed to use `getline` -You don’t have to: + You don’t have to: -- be able to move the cursor + - be able to move the cursor -Help + Help #### Learners who are done with "6. Simple shell 0.1.1" -Get a sandbox + Get a sandbox ### 7. Simple shell 0.2.1 -Simple shell 0.2 + + Simple shell 0.2 + -- You are not allowed to use `strtok` + - You are not allowed to use `strtok` -**Repo:** + **Repo:** -- GitHub repository: `simple_shell` + - GitHub repository: `simple_shell` -Help + Help #### Learners who are done with "7. Simple shell 0.2.1" -Get a sandbox + Get a sandbox ### 8. Simple shell 0.4.1 -Simple shell 0.4 + + Simple shell 0.4 + -- handle arguments for the built-in `exit` -- Usage: `exit status`, where `status` is an integer used to exit the - shell + - handle arguments for the built-in `exit` + - Usage: `exit status`, where `status` is an integer used to exit the + shell - + - julien@ubuntu:~/shell$ ./shell_0.4.1 - $ exit 98 - julien@ubuntu:~/shell$ echo $? - 98 - julien@ubuntu:~/shell$ + julien@ubuntu:~/shell$ ./shell_0.4.1 + $ exit 98 + julien@ubuntu:~/shell$ echo $? + 98 + julien@ubuntu:~/shell$ -**Repo:** + **Repo:** -- GitHub repository: `simple_shell` + - GitHub repository: `simple_shell` -Help + Help #### Learners who are done with "8. Simple shell 0.4.1" -Get a sandbox + Get a sandbox ### 9. setenv, unsetenv -Simple shell 1.0 + + Simple shell 1.0 + -Implement the `setenv` and `unsetenv` builtin commands + Implement the `setenv` and `unsetenv` builtin commands -- `setenv` - - Initialize a new environment variable, or modify an existing one - - Command syntax: `setenv VARIABLE VALUE` - - Should print something on stderr on failure -- `unsetenv` - - Remove an environment variable - - Command syntax: `unsetenv VARIABLE` - - Should print something on stderr on failure + - `setenv` + - Initialize a new environment variable, or modify an existing one + - Command syntax: `setenv VARIABLE VALUE` + - Should print something on stderr on failure + - `unsetenv` + - Remove an environment variable + - Command syntax: `unsetenv VARIABLE` + - Should print something on stderr on failure -**Repo:** + **Repo:** -- GitHub repository: `simple_shell` + - GitHub repository: `simple_shell` -Help + Help #### Learners who are done with "9. setenv, unsetenv" -Get a sandbox + Get a sandbox ### 10. cd -Simple shell 1.0 + + Simple shell 1.0 + -Implement the builtin command `cd`: + Implement the builtin command `cd`: -- Changes the current directory of the process. -- Command syntax: `cd [DIRECTORY]` -- If no argument is given to `cd` the command must be interpreted like - `cd $HOME` -- You have to handle the command `cd -` -- You have to update the environment variable `PWD` when you change - directory + - Changes the current directory of the process. + - Command syntax: `cd [DIRECTORY]` + - If no argument is given to `cd` the command must be interpreted like + `cd $HOME` + - You have to handle the command `cd -` + - You have to update the environment variable `PWD` when you change + directory -`man chdir`, `man getcwd` + `man chdir`, `man getcwd` -**Repo:** + **Repo:** -- GitHub repository: `simple_shell` + - GitHub repository: `simple_shell` -Help + Help #### Learners who are done with "10. cd" -Get a sandbox + Get a sandbox ### 11. ; -Simple shell 1.0 + + Simple shell 1.0 + -- Handle the commands separator `;` + - Handle the commands separator `;` - + - alex@~$ ls /var ; ls /var - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ ls /hbtn ; ls /var - ls: cannot access /hbtn: No such file or directory - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ ls /var ; ls /hbtn - backups cache crash lib local lock log mail metrics opt run spool tmp - ls: cannot access /hbtn: No such file or directory - alex@~$ ls /var ; ls /hbtn ; ls /var ; ls /var - backups cache crash lib local lock log mail metrics opt run spool tmp - ls: cannot access /hbtn: No such file or directory - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ + alex@~$ ls /var ; ls /var + backups cache crash lib local lock log mail metrics opt run spool tmp + backups cache crash lib local lock log mail metrics opt run spool tmp + alex@~$ ls /hbtn ; ls /var + ls: cannot access /hbtn: No such file or directory + backups cache crash lib local lock log mail metrics opt run spool tmp + alex@~$ ls /var ; ls /hbtn + backups cache crash lib local lock log mail metrics opt run spool tmp + ls: cannot access /hbtn: No such file or directory + alex@~$ ls /var ; ls /hbtn ; ls /var ; ls /var + backups cache crash lib local lock log mail metrics opt run spool tmp + ls: cannot access /hbtn: No such file or directory + backups cache crash lib local lock log mail metrics opt run spool tmp + backups cache crash lib local lock log mail metrics opt run spool tmp + alex@~$ -**Repo:** + **Repo:** -- GitHub repository: `simple_shell` + - GitHub repository: `simple_shell` -Help + Help #### Learners who are done with "11. ;" -Get a sandbox + Get a sandbox ### 12. && and \|\| -Simple shell 1.0 + - -- Handle the `&&` and `||` shell logical operators - - - - alex@~$ ls /var && ls /var - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ ls /hbtn && ls /var - ls: cannot access /hbtn: No such file or directory - alex@~$ ls /var && ls /var && ls /var && ls /hbtn - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - ls: cannot access /hbtn: No such file or directory - alex@~$ ls /var && ls /var && ls /var && ls /hbtn && ls /hbtn - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - ls: cannot access /hbtn: No such file or directory - alex@~$ - alex@~$ ls /var || ls /var - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ ls /hbtn || ls /var - ls: cannot access /hbtn: No such file or directory - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ ls /hbtn || ls /hbtn || ls /hbtn || ls /var - ls: cannot access /hbtn: No such file or directory - ls: cannot access /hbtn: No such file or directory - ls: cannot access /hbtn: No such file or directory - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ ls /hbtn || ls /hbtn || ls /hbtn || ls /var || ls /var - ls: cannot access /hbtn: No such file or directory - ls: cannot access /hbtn: No such file or directory - ls: cannot access /hbtn: No such file or directory - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ - -**Repo:** - -- GitHub repository: `simple_shell` - -Help + Simple shell 1.0 + + + - Handle the `&&` and `||` shell logical operators + + + + alex@~$ ls /var && ls /var + backups cache crash lib local lock log mail metrics opt run spool tmp + backups cache crash lib local lock log mail metrics opt run spool tmp + alex@~$ ls /hbtn && ls /var + ls: cannot access /hbtn: No such file or directory + alex@~$ ls /var && ls /var && ls /var && ls /hbtn + backups cache crash lib local lock log mail metrics opt run spool tmp + backups cache crash lib local lock log mail metrics opt run spool tmp + backups cache crash lib local lock log mail metrics opt run spool tmp + ls: cannot access /hbtn: No such file or directory + alex@~$ ls /var && ls /var && ls /var && ls /hbtn && ls /hbtn + backups cache crash lib local lock log mail metrics opt run spool tmp + backups cache crash lib local lock log mail metrics opt run spool tmp + backups cache crash lib local lock log mail metrics opt run spool tmp + ls: cannot access /hbtn: No such file or directory + alex@~$ + alex@~$ ls /var || ls /var + backups cache crash lib local lock log mail metrics opt run spool tmp + alex@~$ ls /hbtn || ls /var + ls: cannot access /hbtn: No such file or directory + backups cache crash lib local lock log mail metrics opt run spool tmp + alex@~$ ls /hbtn || ls /hbtn || ls /hbtn || ls /var + ls: cannot access /hbtn: No such file or directory + ls: cannot access /hbtn: No such file or directory + ls: cannot access /hbtn: No such file or directory + backups cache crash lib local lock log mail metrics opt run spool tmp + alex@~$ ls /hbtn || ls /hbtn || ls /hbtn || ls /var || ls /var + ls: cannot access /hbtn: No such file or directory + ls: cannot access /hbtn: No such file or directory + ls: cannot access /hbtn: No such file or directory + backups cache crash lib local lock log mail metrics opt run spool tmp + alex@~$ + + **Repo:** + + - GitHub repository: `simple_shell` + + Help #### Learners who are done with "12. && and \|\|" -Get a sandbox + Get a sandbox ### 13. alias -Simple shell 1.0 + + Simple shell 1.0 + -- Implement the `alias` builtin command -- Usage: `alias [name[='value'] ...]` - - `alias`: Prints a list of all aliases, one per line, in the form - `name='value'` - - `alias name [name2 ...]`: Prints the aliases `name`, `name2`, - etc 1 per line, in the form `name='value'` - - `alias name='value' [...]`: Defines an alias for each `name` - whose `value` is given. If `name` is already an alias, replaces - its value with `value` + - Implement the `alias` builtin command + - Usage: `alias [name[='value'] ...]` + - `alias`: Prints a list of all aliases, one per line, in the form + `name='value'` + - `alias name [name2 ...]`: Prints the aliases `name`, `name2`, + etc 1 per line, in the form `name='value'` + - `alias name='value' [...]`: Defines an alias for each `name` + whose `value` is given. If `name` is already an alias, replaces + its value with `value` -**Repo:** + **Repo:** -- GitHub repository: `simple_shell` + - GitHub repository: `simple_shell` -Help + Help #### Learners who are done with "13. alias" -Get a sandbox + Get a sandbox ### 14. Variables -Simple shell 1.0 + + Simple shell 1.0 + -- Handle variables replacement -- Handle the `$?` variable -- Handle the `$$` variable + - Handle variables replacement + - Handle the `$?` variable + - Handle the `$$` variable - + - julien@ubuntu:~/shell$ ./hsh - $ ls /var - backups cache crash lib local lock log mail metrics opt run snap spool tmp - $ echo $? - 0 - $ echo $$ - 5104 - $ echo $PATH - /home/julien/bin:/home/julien/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin - $ exit - julien@ubuntu:~/shell$ + julien@ubuntu:~/shell$ ./hsh + $ ls /var + backups cache crash lib local lock log mail metrics opt run snap spool tmp + $ echo $? + 0 + $ echo $$ + 5104 + $ echo $PATH + /home/julien/bin:/home/julien/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin + $ exit + julien@ubuntu:~/shell$ -Help + Help #### Learners who are done with "14. Variables" -Get a sandbox + Get a sandbox ### 15. Comments -Simple shell 1.0 + + Simple shell 1.0 + - Handle comments (`#`) - + - julien@ubuntu:~/shell$ sh - $ echo $$ # ls -la - 5114 - $ exit - julien@ubuntu:~/shell$ + julien@ubuntu:~/shell$ sh + $ echo $$ # ls -la + 5114 + $ exit + julien@ubuntu:~/shell$ -Help + Help #### Learners who are done with "15. Comments" -Get a sandbox + Get a sandbox ### 16. File as input -Simple shell 1.0 + + Simple shell 1.0 + -- Usage: `simple_shell [filename]` -- Your shell can take a file as a command line argument -- The file contains all the commands that your shell should run before - exiting -- The file should contain one command per line -- In this mode, the shell should not print a prompt and should not - read from `stdin` + - Usage: `simple_shell [filename]` + - Your shell can take a file as a command line argument + - The file contains all the commands that your shell should run before + exiting + - The file should contain one command per line + - In this mode, the shell should not print a prompt and should not + read from `stdin` -**Repo:** + **Repo:** -- GitHub repository: `simple_shell` + - GitHub repository: `simple_shell` -Help + Help #### Learners who are done with "16. File as input" -Get a sandbox + Get a sandbox #### Recommended Sandbox @@ -834,78 +834,78 @@ Get a sandbox ### Ubuntu 20.04Asleep -Basic Ubuntu 20.04, with vim, emacs, curl, wget and all needed for -Foundations + Basic Ubuntu 20.04, with vim, emacs, curl, wget and all needed for + Foundations -Copyright © 2023 ALX, All rights reserved. + Copyright © 2023 ALX, All rights reserved. #### Markdown Guide -
+
- - -## Tasks - - Write a beautiful code that passes the Betty checks - -
- -
- -
- - **Repo:** - - - GitHub repository: `simple_shell` - - Help - -#### Learners who are done with "0. Betty would be proud" - - Get a sandbox - -### 1. Simple shell 0.1 - - Write a UNIX command line interpreter. - - - Usage: `simple_shell` - - Your Shell should: - - - Display a prompt and wait for the user to type a command. A command - line always ends with a new line. - - The prompt is displayed again each time a command has been executed. - - The command lines are simple, no semicolons, no pipes, no - redirections or any other advanced features. - - The command lines are made only of one word. No arguments will be - passed to programs. - - If an executable cannot be found, print an error message and display - the prompt again. - - Handle errors. -- You have to handle the “end of file” condition (`Ctrl+D`) - - You don’t have to: - - - use the `PATH` - - implement built-ins - - handle special characters : `"`, `'`, `` ` ``, `\`, `*`, `&`, `#` - - be able to move the cursor - - handle commands with arguments - - *`execve` will be the core part of your Shell, don’t forget to pass the - environ to it…* - - julien@ubuntu:~/shell$ ./shell -#cisfun$ ls - ./shell: No such file or directory -#cisfun$ /bin/ls - barbie_j env-main.c exec.c fork.c pid.c ppid.c prompt prompt.c shell.c stat.c wait - env-environ.c exec fork mypid ppid printenv promptc shell stat test_scripting.sh wait.c -#cisfun$ /bin/ls -l - ./shell: No such file or directory -#cisfun$ ^[[D^[[D^[[D - ./shell: No such file or directory -#cisfun$ ^[[C^[[C^[[C^[[C - ./shell: No such file or directory -#cisfun$ exit - ./shell: No such file or directory -#cisfun$ ^C - julien@ubuntu:~/shell$ echo "/bin/ls" | ./shell - barbie_j env-main.c exec.c fork.c pid.c ppid.c prompt prompt.c shell.c stat.c wait - env-environ.c exec fork mypid ppid printenv promptc shell stat test_scripting.sh wait.c -#cisfun$ julien@ubuntu:~/shell$ - - **Repo:** - - - GitHub repository: `simple_shell` - - Help - - -#### Learners who are done with "1. Simple shell 0.1" - - Get a sandbox - -### 2. Simple shell 0.2 - - Simple shell 0.1 + - - - Handle command lines with arguments - - **Repo:** - - - GitHub repository: `simple_shell` - - Help - -#### Learners who are done with "2. Simple shell 0.2" - - Get a sandbox - -### 3. Simple shell 0.3 - - Simple shell 0.2 + - - - Handle the `PATH` - - `fork` must not be called if the command doesn’t exist - - - - julien@ubuntu:~/shell$ ./shell_0.3 - :) /bin/ls - barbie_j env-main.c exec.c fork.c pid.c ppid.c prompt prompt.c shell_0.3 stat test_scripting.sh wait.c - env-environ.c exec fork mypid ppid printenv promptc shell shell.c stat.c wait - :) ls - barbie_j env-main.c exec.c fork.c pid.c ppid.c prompt prompt.c shell_0.3 stat test_scripting.sh wait.c - env-environ.c exec fork mypid ppid printenv promptc shell shell.c stat.c wait - :) ls -l /tmp - total 20 - -rw------- 1 julien julien 0 Dec 5 12:09 config-err-aAMZrR - drwx------ 3 root root 4096 Dec 5 12:09 systemd-private-062a0eca7f2a44349733e78cb4abdff4-colord.service-V7DUzr - drwx------ 3 root root 4096 Dec 5 12:09 systemd-private-062a0eca7f2a44349733e78cb4abdff4-rtkit-daemon.service-ANGvoV - drwx------ 3 root root 4096 Dec 5 12:07 systemd-private-062a0eca7f2a44349733e78cb4abdff4-systemd-timesyncd.service-CdXUtH - -rw-rw-r-- 1 julien julien 0 Dec 5 12:09 unity_support_test.0 - :) ^C - julien@ubuntu:~/shell$ - - - **Repo:** - - - GitHub repository: `simple_shell` - - Help - -#### Learners who are done with "3. Simple shell 0.3" - - Get a sandbox - -### 4. Simple shell 0.4 - - Simple shell 0.3 + - - - Implement the `exit` built-in, that exits the shell - - Usage: `exit` - - You don’t have to handle any argument to the built-in `exit` - - - **Repo:** - - - GitHub repository: `simple_shell` - - Help - -#### Learners who are done with "4. Simple shell 0.4" - - Get a sandbox - -### 5. Simple shell 1.0 - - Simple shell 0.4 + - - - Implement the `env` **built-in**, that prints the current - environment - - - - julien@ubuntu:~/shell$ ./simple_shell - $ env - USER=julien - LANGUAGE=en_US - SESSION=ubuntu - COMPIZ_CONFIG_PROFILE=ubuntu - SHLVL=1 - HOME=/home/julien - C_IS=Fun_:) - DESKTOP_SESSION=ubuntu - LOGNAME=julien - TERM=xterm-256color - PATH=/home/julien/bin:/home/julien/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin - DISPLAY=:0 - $ exit - julien@ubuntu:~/shell$ - - - **Repo:** - - - GitHub repository: `simple_shell` - - Help - - -#### Learners who are done with "5. Simple shell 1.0" - - Get a sandbox - -### 6. Simple shell 0.1.1 - - Simple shell 0.1 + - - - Write your own `getline` function - - Use a buffer to read many chars at once and call the least possible - the `read` system call - - You will need to use `static` variables - - You are not allowed to use `getline` - - You don’t have to: - - - be able to move the cursor - - Help - -#### Learners who are done with "6. Simple shell 0.1.1" - - Get a sandbox - -### 7. Simple shell 0.2.1 - - Simple shell 0.2 + - - - You are not allowed to use `strtok` - - **Repo:** - - - GitHub repository: `simple_shell` - - Help - -#### Learners who are done with "7. Simple shell 0.2.1" - - Get a sandbox - -### 8. Simple shell 0.4.1 - - Simple shell 0.4 + - - - handle arguments for the built-in `exit` - - Usage: `exit status`, where `status` is an integer used to exit the - shell - - - - julien@ubuntu:~/shell$ ./shell_0.4.1 - $ exit 98 - julien@ubuntu:~/shell$ echo $? - 98 - julien@ubuntu:~/shell$ - - **Repo:** - - - GitHub repository: `simple_shell` - - Help - -#### Learners who are done with "8. Simple shell 0.4.1" - - Get a sandbox - -### 9. setenv, unsetenv - - Simple shell 1.0 + - - Implement the `setenv` and `unsetenv` builtin commands - - - `setenv` - - Initialize a new environment variable, or modify an existing one - - Command syntax: `setenv VARIABLE VALUE` - - Should print something on stderr on failure - - `unsetenv` - - Remove an environment variable - - Command syntax: `unsetenv VARIABLE` - - Should print something on stderr on failure - - **Repo:** - - - GitHub repository: `simple_shell` - - Help - -#### Learners who are done with "9. setenv, unsetenv" - - Get a sandbox - -### 10. cd - - Simple shell 1.0 + - - Implement the builtin command `cd`: - - - Changes the current directory of the process. - - Command syntax: `cd [DIRECTORY]` - - If no argument is given to `cd` the command must be interpreted like - `cd $HOME` - - You have to handle the command `cd -` - - You have to update the environment variable `PWD` when you change - directory - - `man chdir`, `man getcwd` - - **Repo:** - - - GitHub repository: `simple_shell` - - Help - -#### Learners who are done with "10. cd" - - Get a sandbox - -### 11. ; - - Simple shell 1.0 + - - - Handle the commands separator `;` - - - - alex@~$ ls /var ; ls /var - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ ls /hbtn ; ls /var - ls: cannot access /hbtn: No such file or directory - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ ls /var ; ls /hbtn - backups cache crash lib local lock log mail metrics opt run spool tmp - ls: cannot access /hbtn: No such file or directory - alex@~$ ls /var ; ls /hbtn ; ls /var ; ls /var - backups cache crash lib local lock log mail metrics opt run spool tmp - ls: cannot access /hbtn: No such file or directory - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ - - **Repo:** - - - GitHub repository: `simple_shell` - - Help - -#### Learners who are done with "11. ;" - - Get a sandbox - -### 12. && and \|\| - - Simple shell 1.0 + - - - Handle the `&&` and `||` shell logical operators - - - - alex@~$ ls /var && ls /var - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ ls /hbtn && ls /var - ls: cannot access /hbtn: No such file or directory - alex@~$ ls /var && ls /var && ls /var && ls /hbtn - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - ls: cannot access /hbtn: No such file or directory - alex@~$ ls /var && ls /var && ls /var && ls /hbtn && ls /hbtn - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - backups cache crash lib local lock log mail metrics opt run spool tmp - ls: cannot access /hbtn: No such file or directory - alex@~$ - alex@~$ ls /var || ls /var - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ ls /hbtn || ls /var - ls: cannot access /hbtn: No such file or directory - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ ls /hbtn || ls /hbtn || ls /hbtn || ls /var - ls: cannot access /hbtn: No such file or directory - ls: cannot access /hbtn: No such file or directory - ls: cannot access /hbtn: No such file or directory - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ ls /hbtn || ls /hbtn || ls /hbtn || ls /var || ls /var - ls: cannot access /hbtn: No such file or directory - ls: cannot access /hbtn: No such file or directory - ls: cannot access /hbtn: No such file or directory - backups cache crash lib local lock log mail metrics opt run spool tmp - alex@~$ - - **Repo:** - - - GitHub repository: `simple_shell` - - Help - -#### Learners who are done with "12. && and \|\|" - - Get a sandbox - -### 13. alias - - Simple shell 1.0 + - - - Implement the `alias` builtin command - - Usage: `alias [name[='value'] ...]` - - `alias`: Prints a list of all aliases, one per line, in the form - `name='value'` - - `alias name [name2 ...]`: Prints the aliases `name`, `name2`, - etc 1 per line, in the form `name='value'` - - `alias name='value' [...]`: Defines an alias for each `name` - whose `value` is given. If `name` is already an alias, replaces - its value with `value` - - **Repo:** - - - GitHub repository: `simple_shell` - - Help - -#### Learners who are done with "13. alias" - - Get a sandbox - -### 14. Variables - - Simple shell 1.0 + - - - Handle variables replacement - - Handle the `$?` variable - - Handle the `$$` variable - - - - julien@ubuntu:~/shell$ ./hsh - $ ls /var - backups cache crash lib local lock log mail metrics opt run snap spool tmp - $ echo $? - 0 - $ echo $$ - 5104 - $ echo $PATH - /home/julien/bin:/home/julien/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin - $ exit - julien@ubuntu:~/shell$ - - Help - -#### Learners who are done with "14. Variables" - - Get a sandbox - -### 15. Comments - - Simple shell 1.0 + - -- Handle comments (`#`) - - - - julien@ubuntu:~/shell$ sh - $ echo $$ # ls -la - 5114 - $ exit - julien@ubuntu:~/shell$ - - - Help - -#### Learners who are done with "15. Comments" - - Get a sandbox - -### 16. File as input - - Simple shell 1.0 + - - - Usage: `simple_shell [filename]` - - Your shell can take a file as a command line argument - - The file contains all the commands that your shell should run before - exiting - - The file should contain one command per line - - In this mode, the shell should not print a prompt and should not - read from `stdin` - - - **Repo:** - - - GitHub repository: `simple_shell` - - Help - -#### Learners who are done with "16. File as input" - - Get a sandbox - -#### Recommended Sandbox - -### 1 image(1/2 Sandboxes spawned) - - -### Ubuntu 20.04Asleep - - - Basic Ubuntu 20.04, with vim, emacs, curl, wget and all needed for - Foundations - - Copyright © 2023 ALX, All rights reserved. - -#### Markdown Guide - -
- -