Files created by the tester were not created, contradicting existing new line character condition for the echo cmnd [Single quotes #ni6]

Hi,
In the Implement echo#IZ3, it is mentioned that “The echo builtin prints its arguments to stdout, with spaces between them, and a newline (\n) at the end.“
But this is failing in the #ni6 (1st ss).

After encountering the issue above I remove the new line character which passed some of the tests:

In the above ss, although the error conveys that the single quotes were handled as desired, you can see it failed tests as such dirs/files were not created.

How executable command is handled:

func (c *cmnd) execute() {

    cmd := exec.Command(c.name, c.arguments...)

output, err := cmd.CombinedOutput()

fmt.Printf("%s", string(output))

if err != nil {

log.Fatalf("failed to run %s with %s", c.name, strings.Join(c.arguments, " "))

    }

}

How echo is handled:

func (c *cmnd) echo() {

    output := strings.Join(c.arguments, " ")

// fmt.Printf("my output: %s,len of output: %d ,len of arguments array: %d", output, len(output), len(c.arguments))

//older implementation #IZ3
//fmt.Fprintf(os.Stdout, "%s\n", output) 

// new implementation 
fmt.Fprintf(os.Stdout, "%s", output)

}

How single quote is handled:

func sanitiseArgs(argumentString string) string {

    // the boolean flag of single quote represents whether to consider

// the string as literal or not in the window iterated

// if true -> yes, false -> no.

chars := make([]rune, 0)

singleQuote := false

lastRune := '\x00'

for _, r := range argumentString {

currentRune := r

if currentRune == '\'' {

singleQuote = true

lastRune = currentRune

continue

        }

if singleQuote {

chars = append(chars, currentRune)

lastRune = currentRune

        } else {

if currentRune == lastRune && currentRune == ' ' {

continue

            }

chars = append(chars, currentRune)

lastRune = currentRune

        }


    }


return string(chars)


}

Is the above code adding an extra new line?

TIA

Hey @vardey, I added a couple of logs here:

Looks like args isn’t being parsed correctly. The correct length should be 3 instead of 1.


For context, our tester has been validated against several real-world shells across different operating systems. You can confirm those files exist like this:

Let me know if anything’s still unclear or if you’d like to dig deeper!

Hey @andy1li ,
My initial understanding was that exec.Command should be able to process all of them when given as a space separated string. I have made the changes so that the function receives arguments separately. As logged out in the 2nd ss that there are 3 arguments. One of them gets processed resulting in “pear orange“ (below Received in red).

@vardey Looks like there are some untrimmed spaces in args:

1 Like

Thanks!

1 Like

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