[shell] GO Single quotes #ni6

I’m stuck on Stage Single quotes #ni6

When I try on my side it works, I can display everything, launch a binary, pass arguments etc…
I don’t understood the point of this error and i’ve been digging for few hours and I’m still stuck.
Any help is appreciated, thank you

Here are my logs:

[compile] Moved ./.codecrafters/run.sh → ./your_program.sh
[compile] Compilation successful.
[tester::#NI6] Running tests for Stage #NI6 (Quoting - Single quotes)
[tester::#NI6] [setup] export PATH=/tmp/apple/banana/pear:$PATH
[tester::#NI6] Running ./your_program.sh
[tester::#NI6] [setup] echo -n "apple grape." > "/tmp/baz/f   57"
[tester::#NI6] [setup] echo -n "banana grape." > "/tmp/baz/f   15"
[tester::#NI6] [setup] echo -n "blueberry raspberry." > "/tmp/baz/f   82"
[your-program] $ echo 'shell world'
[your-program] shell world
[tester::#NI6] ✓ Received expected response
[your-program] $ echo world     script
[your-program] world script
[tester::#NI6] ✓ Received expected response
[your-program] $ echo 'test     hello' 'script''shell'
[your-program] test     hello scriptshell
[tester::#NI6] ✓ Received expected response
[your-program] $ cat '/tmp/baz/f   57' '/tmp/baz/f   15' '/tmp/baz/f   82'
[your-program] apple grape.banana grape.blueberry raspberry.
[tester::#NI6] ✓ Received expected response
[your-program] $ 
[tester::#NI6] Test passed.
[tester::#GP4] Running tests for Stage #GP4 (Navigation - The cd builtin: Home directory)
[tester::#GP4] Running ./your_program.sh
[your-program] $ cd /tmp/apple/banana/strawberry
[your-program] $ pwd
[your-program] /tmp/apple/banana/strawberry
[tester::#GP4] Received current working directory response
[your-program] $ cd ~
[your-program] $ pwd
[your-program] /tmp/apple/mango/orange
[tester::#GP4] Received current working directory response
[your-program] $ 
[tester::#GP4] Test passed.
[tester::#GQ9] Running tests for Stage #GQ9 (Navigation - The cd builtin: Relative paths)
[tester::#GQ9] Running ./your_program.sh
[your-program] $ cd /tmp/apple
[your-program] $ pwd
[your-program] /tmp/apple
[tester::#GQ9] Received current working directory response
[your-program] $ cd ./strawberry/pineapple
[your-program] $ pwd
[your-program] /tmp/apple/strawberry/pineapple
[tester::#GQ9] Received current working directory response
[your-program] $ cd ../../../
[your-program] $ pwd
[your-program] /tmp
[tester::#GQ9] Received current working directory response
[your-program] $ 
[tester::#GQ9] Test passed.
[tester::#RA6] Running tests for Stage #RA6 (Navigation - The cd builtin: Absolute paths)
[tester::#RA6] Running ./your_program.sh
[your-program] $ cd /tmp/strawberry/mango/grape
[your-program] $ pwd
[your-program] /tmp/strawberry/mango/grape
[tester::#RA6] Received current working directory response
[your-program] $ cd /non-existing-directory
[your-program] cd: /non-existing-directory: No such file or directory
[tester::#RA6] ✓ Received error message
[your-program] $ 
[tester::#RA6] Test passed.
[tester::#EI0] Running tests for Stage #EI0 (Navigation - The pwd builtin)
[tester::#EI0] Running ./your_program.sh
[your-program] $ type pwd
[your-program] pwd is a shell builtin
[tester::#EI0] ✓ Received expected response
[your-program] $ pwd
[your-program] /app
[tester::#EI0] ✓ Received current working directory response
[your-program] $ 
[tester::#EI0] Test passed.
[tester::#IP1] Running tests for Stage #IP1 (Run a program)
[tester::#IP1] [setup] export PATH=/tmp/foo:$PATH
[tester::#IP1] [setup] Available executables:
[tester::#IP1] [setup] - custom_exe_6435
[tester::#IP1] Running ./your_program.sh
[your-program] $ custom_exe_6435 Maria
[your-program] Program was passed 2 args (including program name).
[your-program] Arg #0 (program name): /tmp/foo/custom_exe_6435
[tester::#IP1] Output does not match expected value.
[tester::#IP1] Expected: "Arg #0 (program name): custom_exe_6435"
[tester::#IP1] Received: "Arg #0 (program name): /tmp/foo/custom_exe_6435"
[your-program] Arg #1: Maria
[your-program] Program Signature: 7452853442
[your-program] $ 
[tester::#IP1] Assertion failed.
[tester::#IP1] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)

And here’s a snippet of my code:

func ExecBin(path string, args []string){
  cmd := exec.Command(path, args...)
  cmd.Stdout = os.Stdout
  cmd.Stderr = os.Stderr

  cmd.Run()
}

[...]

    switch command.RootCommand(){
    case "echo":
      command.Echo()

    case "type":
      command.Type()

    case "pwd":
      command.Pwd()

    case "cd":
      command.Cd()

      default:
      path := command.CheckLocalPath(command.RootCommand()) 
      // fmt.Println("path: ", path)
      if path != ""{
        formattedCmd := RemoveWhiteSpace(command.Args())
        // formattedCmd := command.Args()

        // fmt.Println("formattedCMD: ", formattedCmd)
        ExecBin(path, formattedCmd)
      }else{
        fmt.Printf("%s: command not found\n", command.RootCommand())
      }
        
  }

Hi @0xbochi, the error message says that the expected arg 0 is the command name, but instead the path was provided.

To fix this, the code needs to be updated accordingly:

1 Like

Wow it worked!

Thank you so much for your help, now I need to understan how I can refactor that because it seems I did a useless step with my CheckLocalPath function if it works without.

Well, one more time thank you so much for your help and your fast answer

1 Like

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