I am not able to complete this The cd builtin: Home directory

I’m stuck on Stage #(The cd builtin: Home directory #gp4
).

I’ve tried apply different function to get to home directory but still, it is showing error in the test cases

Here are my logs:

$ cd /tmp/blueberry/apple/mango
[your-program] $ pwd
[your-program] /tmp/blueberry/apple/mango
[tester::#GP4] Received current working directory response
[your-program] $ cd ~
[your-program] $ pwd
[your-program] /app
[tester::#GP4] Output does not match expected value.
[tester::#GP4] Expected: "/tmp/grape/blueberry/pineapple"
[tester::#GP4] Received: "/app"
[your-program] $ 
[tester::#GP4] Assertion failed.
[tester::#GP4] Test failed

And here’s a snippet of my code:

    private static final String homeDirectory = System.getProperty("user.home");

   private static void handleCdCommand(String parameter) {
        if (parameter.isEmpty() || parameter.equals("~")) {
            workingDirectory = homeDirectory;
            return;
        }

Hi @Seya-Mali, could you upload your code to GitHub and share the link? It will be much easier to debug if I can run it directly.

hi @andy1li did you find the what is wrong with my code?

@Seya-Mali You can replace System.getProperty("user.home") with System.getenv("HOME").

The shell you’re implementing is expected to respect the $HOME environment variable.

However, System.getProperty("user.home") only uses $HOME as a fallback source, which means you’ll need to explicitly rely on System.getenv("HOME") for consistent behavior.

the System.getenv(“HOME”) function is giving null.

Are you by any chance using Windows to test it locally? The $HOME environment variable is specific to Linux and doesn’t exist on Windows.

yes it is windows

On Windows, it’s called USERPROFILE.

To accommodate both systems, you can check for both USERPROFILE and HOME, selecting the one that is not null.

this is the test case result
Output does not match expected value.
remote: [tester::#GP4] Expected: “/tmp/pear/pear/apple”
remote: [tester::#GP4] Received: “null”
remote: [your-program] $
remote: [tester::#GP4] Assertion failed.
remote: [tester::#GP4] Test failed

this is the result in my vscode
cd ~
$ pwd
C:\Users\seyam

it is still showing null when i replaced
private static final String homeDirectory = System.getProperty(“user.home”);
with
private static final String homeDirectory = System.getenv(“USERPROFILE”);

To pass the test which runs on Linux, you’ll need HOME.

To get correct result on your Windows machine, you’ll need USERPROFILE.

To accommodate both systems, you can check for both USERPROFILE and HOME, and then select the one that is not null.

both are showing null in the test

Well, feel free to share a screenshot of null in the test when you use “HOME”.

Our system shows that your code was using “USERPROFILE” for the screenshot above expecting “/tmp/pear/pear/apple”.

When it’s “HOME”, your code passed tests for #GP4 (Navigation - The cd builtin: Home directory):

However, it did fail an earlier stage #IP1 (Run a program):


it is giving error in previously passes test

Failing #IP1 (Run a program) is a separate issue.

You can use command directly instead of path in executeExternalCommand:

1 Like

Thank you so much

1 Like

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