4 ms·
Yeah it's particular about the output that it expects.
by zoidb 10y ago
Yeah it's particular about the output that it expects.
- garettmd 10y agoI guess my point is that "ls" shouldn't be an answer. Typically it will print out multiple files on a line. If it's just checking for output and not the actual command someone entered, there should probably be more than one file in the directory to show that it will actually print one file per line.
- zoidb 10y agoBecause it is executed outside of a terminal (the execution isn't in javascript) you get a single column output. Probably would be better to be more specific in the descriptions, thanks for the suggestion.
- zokier 10y agoThe mostly correct answer is `ls -1`. Just mostly, because it falls to the classic unix trap (filenames can contain almost anything) which also shows that the challenge is ill defined. What is the expected result if the filename contains newlines? And this is not just some hypothetical scenario, just today at work I encountered a file with cursor movement terminal escape sequences in the filename.
- lisivka 10y ago`ls -1b` should work correctly in your case. Option -b (or --escape) enables C-style escapes. IMHO, it should be on by default.
- saghm 10y agoAlthough it often doesn't get printed like that, shells do consider the output of `ls` to be multiple lines. Try doing `ls > foo.txt` and looking at the output file (or more directly, `ls | wc -l`).
- jjnoakes 10y agoThat isn't the shell considering the output one per line. ls will change the way it writes its output if it detects that stdout is a tty versus a pipe or redirect.
- JoshTriplett 10y agoIt seems to accept any command that produces the expected output, though. That question should specifically say that it only wants the filenames, which would make it clear that `ls -l` doesn't produce the desired result.