Why my code cannot access or received the echo setup for /tmp and or my cat command not founding the file

I’m stuck on Stage #NI6.

I’ve tried … every possible way of do it manually and logically for me (with addition of ai support).

Here are my logs:

remote: [tester::#NI6] Running tests for Stage #NI6 (Quoting - Single quotes)
remote: [tester::#NI6] [setup] export PATH=/tmp/raspberry/pineapple/raspberry:$PATH
remote: [tester::#NI6] Running ./your_program.sh
remote: [tester::#NI6] [setup] echo -n "grape banana." > "/tmp/quz/f   14"
remote: [tester::#NI6] [setup] echo -n "apple blueberry." > "/tmp/quz/f   94"
remote: [tester::#NI6] [setup] echo -n "blueberry pear." > "/tmp/quz/f   63"
remote: [your-program] $ echo 'world example'
remote: [your-program] world example
remote: [tester::#NI6] ✓ Received expected response
remote: [your-program] $ echo example     test
remote: [your-program] example test
remote: [tester::#NI6] ✓ Received expected response
remote: [your-program] $ echo 'hello     shell' 'test''world'
remote: [your-program] hello     shell testworld
remote: [tester::#NI6] ✓ Received expected response
remote: [your-program] $ cat '/tmp/quz/f   14' '/tmp/quz/f   94' '/tmp/quz/f   63'
remote: [your-program] cat: '/tmp/quz/f: No such file or directory
remote: [tester::#NI6] Output does not match expected value.
remote: [tester::#NI6] Expected: "grape banana.apple blueberry.blueberry pear."
remote: [tester::#NI6] Received: "cat: '/tmp/quz/f: No such file or directory"
remote: [your-program] cat: : No such file or directory
remote: [your-program] cat: : No such file or directory
remote: [your-program] cat: 14': No such file or directory
remote: [your-program] cat: '/tmp/quz/f: No such file or directory
remote: [your-program] cat: : No such file or directory
remote: [your-program] cat: : No such file or directory
remote: [your-program] cat: 94': No such file or directory
remote: [your-program] cat: '/tmp/quz/f: No such file or directory
remote: [your-program] cat: : No such file or directory
remote: [your-program] cat: : No such file or directory
remote: [your-program] cat: 63': No such file or directory
remote: [your-program] cat: command not found
remote: [your-program] $
remote: [tester::#NI6] Assertion failed.
remote: [tester::#NI6] Test failed
remote:
remote: Try our CLI to run tests faster without Git: https://codecrafters.io/cli
remote:
remote: View our article on debugging test failures: https://codecrafters.io/debug
remote:

And here’s a snippet of my code:

func handleEchoCommand(args []string) {
	if len(args) == 1 {
		// prints current (last) exit code when argument is $?
		if args[0] == "$?" {
			return
		}
	}

	// initialized result array for the quoted arguments
	var res []string
	isClosedDoubleQuote := true
	isClosedSingleQuote := true
	for _, arg := range args {

		if strings.Contains(arg, "'") || strings.Contains(arg, "\"") {
			totalDoubleQuote := strings.Count(arg, "\"")
			totalSingleQuote := strings.Count(arg, "'")
			// check if the argument is quoted
			arg = strings.Trim(arg, "'\"")
			arg = strings.ReplaceAll(arg, "'", "")
			if totalDoubleQuote%2 == 1 {
				isClosedDoubleQuote = false
			}
			if totalSingleQuote%2 == 1 {
				isClosedSingleQuote = false
			}
			res = append(res, arg)
			continue
		}

		if !isClosedDoubleQuote || !isClosedSingleQuote && len(arg) == 0 {
			res = append(res, "")
			continue
		}

		// check if the argument is quoted
		arg = strings.ReplaceAll(arg, "\\", "")
		// collecting all the the quoted arguments
		if len(arg) > 0 {
			res = append(res, arg)
		}
	}
	// join the array into a string
	join_res := strings.Join(res, " ")

	fmt.Fprintf(os.Stdout, join_res+"\n")
}

or is it because my os is windows and the cat cannot receive it because the path is in \ and not / ? and if it true, how to fix it?

or is it because my os is windows and the cat cannot receive it because the path is in \ and not / ? and if it true, how to fix it?

Hey @Aergiaaa, that could be the issue! Have you tried replacing \ with / in the path?

If you’d like me to take a closer look, could you upload your code to GitHub and share the link? It will be much easier to debug if I can run it directly.

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

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