Subject: Stuck on CodeRoad "Learn Bash Scripting by Building Five Programs" – first step won't pass

Hi everyone,

I’ve been stuck for hours on the very first step of the “Learn Bash Scripting by Building Five Programs” course on freeCodeCamp (the CodeRoad interactive tutorial). The task is simple: in the countdown.sh script, change the if condition to check if the first argument is greater than zero using [[ $1 -gt 0 ]]. The script should then echo the argument if true, or a message if false.

What I’ve tried:

· I’ve written the script exactly as instructed:

#!/bin/bash

# Program that counts down to zero from a given argument

if [[ $1 -gt 0 ]]
then
echo $1
else
echo Include a positive integer as the first argument.
fi

· When I run bash countdown.sh 5 in the terminal, it correctly outputs 5.
· I’ve used cat -A countdown.sh to check for hidden characters – no ^M, only $ at line ends.
· I ran file countdown.sh – it says ASCII text executable.
· bash -n countdown.sh shows no syntax errors.
· I tried both [[ … ]] and [ … ] (single brackets).
· I deleted any extra backup files like countdown.sh.save.
· I used sed -i ‘s/\r$//’ countdown.sh to ensure no Windows line endings.
· I even reset the project multiple times and retyped the code manually (no copy-paste).
· I also tried the simpler version from the tutorial video (with -le 5 and echo true/false) – but that also didn’t pass.

The problem: Every time I click Run, the test fails with the message:
Your script should have the suggested “if/else” statement added correctly
(no more details). The terminal shows no errors, and the script works perfectly when executed manually.

What I see in the editor: The file content looks correct, and there are no red squiggles. But the CodeRoad test just won’t accept it.

I suspect it might be something environmental – maybe the test expects a very specific format (like no blank lines, or a particular indentation) or there’s a caching issue. I’ve tried refreshing the page and using incognito mode, but no luck.

Has anyone else encountered this? Any ideas on what might be wrong or how to debug further? I’d really appreciate any help!

Thanks in advance.

I just want to clarify something, because you have some code from further steps included as code in this topic. But, in your screenshot, the code is correct for this step.

Are you using the following code in this step? Because this particular step is very specific.

#!/bin/bash


# Program that counts down to zero from a given argument


if [[ $1 -gt 0 ]]
then
  echo true
else
  echo false
fi
1 Like

Hi marcusparsons,

Thank you so much for your help! You were right – the code was correct, but the issue was that the file didn’t have execute permissions.

I was only testing with bash countdown.sh 5 which worked fine, but the automated test runs the script directly with ./countdown.sh. After running chmod +x countdown.sh, the test passed immediately!

This might help others who are stuck on the same step. Always check file permissions if the code looks correct but the test won’t pass.

Thanks again!

1 Like

I’m glad to know you found the solution! Have a great day!

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