From daa6997732d142334f0ea21f89ddc2749376e3a1 Mon Sep 17 00:00:00 2001 From: Andy Li <1450947+andy1li@users.noreply.github.com> Date: Thu, 26 Jun 2025 15:44:36 +0800 Subject: [PATCH 1/3] Update command handling instructions in course-definition.yml Enhance the command execution logic by specifying behavior for commands with and without execute permissions. The updated instructions clarify that commands without execute permissions will be skipped, while those with permissions will print their path. This aims to improve user understanding of command execution outcomes. --- course-definition.yml | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/course-definition.yml b/course-definition.yml index d07f9a2..c54c9bb 100644 --- a/course-definition.yml +++ b/course-definition.yml @@ -314,7 +314,13 @@ stages: [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) is an environment variable that specifies a set of directories where executable programs are located. When a command is received, the program should search for the command in the directories listed in the PATH environment variable. - If the command is found, the program should print the path to the command. If the command is not found, the program should print `: not found`. + For example, PATH like `/dir1:/dir2:/dir3` means that the program should search for the command in `/dir1`, then `/dir2`, and finally `/dir3`, in that order. + + Caveat: Not all commands found are necessarily executable. + + - If the command is found (but it does not have execute permissions), the program should skip it and continue searching. + - If the command is found (and it has execute permissions), the program should print the path to the command. + - If the command is not found, the program should print `: not found`. ### Tests @@ -329,8 +335,14 @@ stages: ```bash $ type ls ls is /usr/bin/ls + ``` + + ```bash $ type valid_command valid_command is /usr/local/bin/valid_command + ``` + + ```bash $ type invalid_command invalid_command: not found $ @@ -341,8 +353,9 @@ stages: ### Notes - The actual value of the `PATH` environment variable will be random for each test case. - - `PATH` can contain multiple directories separated by colons (`:`), your program should search for programs in each directory in order and return the first match which has executable permissions. - Some commands, such as `echo`, can exist as both builtin commands and executable files. In such cases, the `type` command should identify them as builtins. + - PATH can include directories that don’t exist on disk, so your code should handle such cases gracefully. + marketing_md: |- In this stage, you'll implement the `type` builtin command for your shell. @@ -1120,8 +1133,11 @@ stages: 1. **Input:** `custom` * The tester types "custom" and presses ``. The tester expects that the prompt line changes to custom_executable . - The tester will verify that your shell correctly completes the command to the external executable file name. - Note the space at the end of the completion. + The tester will verify that your shell correctly completes the command to the external executable file name. Note the space at the end of the completion. + + ### Notes + + - PATH can include directories that don't exist on disk, so your code should handle such cases gracefully. marketing_md: |- In this stage, you'll implement support for autocompleting external executables. From b456fa3431161008ba1aa1b0a7818968d3e40405 Mon Sep 17 00:00:00 2001 From: Andy Li <1450947+andy1li@users.noreply.github.com> Date: Thu, 26 Jun 2025 16:24:57 +0800 Subject: [PATCH 2/3] Clarify shell command execution instructions in course-definition.yml Update the description to specify that the shell should handle command searches and permissions. This change enhances clarity by consistently referring to the shell's role in executing commands and improves user understanding of command handling outcomes. --- course-definition.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/course-definition.yml b/course-definition.yml index c54c9bb..ea56a2a 100644 --- a/course-definition.yml +++ b/course-definition.yml @@ -312,15 +312,15 @@ stages: description_md: |- In this stage, you'll extend the `type` builtin to search for executable files using [PATH](https://en.wikipedia.org/wiki/PATH_(variable)). - [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) is an environment variable that specifies a set of directories where executable programs are located. When a command is received, the program should search for the command in the directories listed in the PATH environment variable. + [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) is an environment variable that specifies a set of directories where executable programs are located. When a command is received, your shell should search for the command in the directories listed in the PATH environment variable. - For example, PATH like `/dir1:/dir2:/dir3` means that the program should search for the command in `/dir1`, then `/dir2`, and finally `/dir3`, in that order. + For example, PATH like `/dir1:/dir2:/dir3` means that your shell should search in `/dir1`, then `/dir2`, and finally `/dir3`, in that order. Caveat: Not all commands found are necessarily executable. - - If the command is found (but it does not have execute permissions), the program should skip it and continue searching. - - If the command is found (and it has execute permissions), the program should print the path to the command. - - If the command is not found, the program should print `: not found`. + - If the command is found (but it does not have execute permissions), your shell should skip it and continue searching. + - If the command is found (and it has execute permissions), your shell should print the path to the command. + - If the command is not found, your shell should print `: not found`. ### Tests From ce29d6df21705bb343ceeb14bd5c0d0c166a3f86 Mon Sep 17 00:00:00 2001 From: Andy Li <1450947+andy1li@users.noreply.github.com> Date: Sat, 28 Jun 2025 15:29:15 +0800 Subject: [PATCH 3/3] Refine command execution instructions in course-definition.yml Update the examples and wording to clarify the shell's behavior when handling commands with and without execute permissions. This change aims to enhance user understanding of command search outcomes and improve consistency in the instructional content. --- course-definition.yml | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/course-definition.yml b/course-definition.yml index ea56a2a..a29a7e4 100644 --- a/course-definition.yml +++ b/course-definition.yml @@ -314,13 +314,11 @@ stages: [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) is an environment variable that specifies a set of directories where executable programs are located. When a command is received, your shell should search for the command in the directories listed in the PATH environment variable. - For example, PATH like `/dir1:/dir2:/dir3` means that your shell should search in `/dir1`, then `/dir2`, and finally `/dir3`, in that order. + For example, if PATH is `/dir1:/dir2:/dir3`, your shell should search in `/dir1`, then `/dir2`, and finally `/dir3`, in that order. - Caveat: Not all commands found are necessarily executable. - - - If the command is found (but it does not have execute permissions), your shell should skip it and continue searching. - - If the command is found (and it has execute permissions), your shell should print the path to the command. - - If the command is not found, your shell should print `: not found`. + - If a matching file is found but it does not have execute permissions, your shell should skip it and continue searching. + - If a matching files is found and it has execute permissions, your shell should print the path to the file. + - If no matching files are found, your shell should print `: not found`. ### Tests @@ -335,14 +333,8 @@ stages: ```bash $ type ls ls is /usr/bin/ls - ``` - - ```bash $ type valid_command valid_command is /usr/local/bin/valid_command - ``` - - ```bash $ type invalid_command invalid_command: not found $