(Kotlin) “Build your own shell” -Stage #NI6 Output does not match expected value

In stage #MG5 the tester checks that cat command is in the path:

[your-program] $ type cat
[your-program] cat is /bin/cat
[tester::#MG5] ✓ Received expected response

But in #NI6 this are my logs:

[tester::#NI6] Running tests for Stage #NI6 (Quoting - Single quotes)
[tester::#NI6] Running ./your_program.sh
[your-program] $ echo 'test world'
[your-program] test world
[tester::#NI6] ✓ Received expected response
[your-program] $ echo world     script
[your-program] world script
[tester::#NI6] ✓ Received expected response
[your-program] $ echo 'example     hello'
[your-program] example     hello
[tester::#NI6] ✓ Received expected response
[tester::#NI6] Writing file "/tmp/bar/f   7" with content "blueberry pear."
[tester::#NI6] Writing file "/tmp/bar/f   2" with content "blueberry strawberry."
[tester::#NI6] Writing file "/tmp/bar/f   33" with content "pear strawberry."
[your-program] $ cat '/tmp/bar/f   7' '/tmp/bar/f   2' '/tmp/bar/f   33'
[your-program] cat: command not found
[tester::#NI6] Output does not match expected value.
[tester::#NI6] Expected: "blueberry pear.blueberry strawberry.pear strawberry."
[tester::#NI6] Received: "cat: command not found"
[your-program] $ 
[tester::#NI6] Assertion failed.
[tester::#NI6] Test failed

link to my code: GitHub - DanielUH2019/codecrafters-shell-kotlin

Hi @DanielUH2019, it turns out there is a /opt/java/openjdk/bin/cat which isn’t executable:

This is clashing with your current logic. You can fix it by moving println outside the forEach loop:

fun executeExternalCommand(command: String, args: List<String>, shellState: ShellState) {
    pathDirectories.forEach { path ->
        ...
    } 
    println("$command: command not found")
}
1 Like

You’re right, thanks!

1 Like