# Bash impementation cpp "Handle invalid commands #cz2" Expected prompt ("$ ") but received ""

**URL:** <https://forum.codecrafters.io/t/bash-impementation-cpp-handle-invalid-commands-cz2-expected-prompt-but-received/15432>\
**Category:** Challenges\
**Created:** [October 23, 2025, 7:17pm UTC](https://forum.codecrafters.io/t/bash-impementation-cpp-handle-invalid-commands-cz2-expected-prompt-but-received/15432 "2025-10-23T19:17:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![norman-at-kbd](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/norman-at-kbd/32/18957_2.png) [@norman-at-kbd](https://forum.codecrafters.io/u/norman-at-kbd)\
**Post date:** [October 23, 2025, 7:17pm UTC](https://forum.codecrafters.io/t/bash-impementation-cpp-handle-invalid-commands-cz2-expected-prompt-but-received/15432/1 "2025-10-23T19:17:35Z")

</div>

The task description:

```auto
In this stage, you'll implement support for printing error messages for invalid commands.

Example:

$ xyz
xyz: command not found

```

when implemented as show in the hint  
`std::getline(std::cin, input);`  
`std::cout << input << “: command not found” << std::endl;`

following test result is shown:  
`[tester::#FF0] Running ./your_program.sh`  
`[your-program] $ invalid_command_1`  
`[your-program] invalid_command_1: command not found`  
`[tester::#FF0] Expected prompt ("$ ") but received “”`  
`[tester::#FF0] Assertion failed.`  
`[tester::#FF0] Test failed`

so over a several attempts it turns out that expected implementation is:  
`std::cout << "$ ";`  
`while(true) {`  
` std::getline(std::cin,input);`  
` std::cout<<cmd_str << “: command not found”<<std::endl;`  
` std::cout << "$ ";`  
`}`

the test tries series of several consequent inputs.  
So I suppose test or description should be updated.

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [October 23, 2025, 7:31pm UTC](https://forum.codecrafters.io/t/bash-impementation-cpp-handle-invalid-commands-cz2-expected-prompt-but-received/15432/3 "2025-10-23T19:31:58Z")

</div>

Hey @norman-at-kbd, the stage **“Handle invalid commands (#cz2)”** doesn’t actually require a loop. It only needs to handle a single input.

Could you confirm if you’re actually referring to **“Implement a REPL (#ff0)”**, where the goal is to repeatedly read and handle commands in a loop.

---

<div class="post-metadata">

**Author:** ![norman-at-kbd](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/norman-at-kbd/32/18957_2.png) [@norman-at-kbd](https://forum.codecrafters.io/u/norman-at-kbd)\
**Post date:** [October 23, 2025, 7:52pm UTC](https://forum.codecrafters.io/t/bash-impementation-cpp-handle-invalid-commands-cz2-expected-prompt-but-received/15432/4 "2025-10-23T19:52:20Z")

</div>

@andy1li you are absolutely right, sorry for the false alarm.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [October 28, 2025, 7:52pm UTC](https://forum.codecrafters.io/t/bash-impementation-cpp-handle-invalid-commands-cz2-expected-prompt-but-received/15432/5 "2025-10-28T19:52:56Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
