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









