News for hackers. Stuff that matters.
Re:Show HN: Command Line Challenge by garettmd on Thursday January 26, 2017 @01:20PM (#13493785)
I was on the 3rd challenge, listing files in a directory, one per line, and it didn't accept "ls -l", but it did accept "ls"
Re:Show HN: Command Line Challenge by brennen on Thursday January 26, 2017 @01:26PM (#13493840)
Same. Seems like the wording on some questions could use tweaking. Not bad overall, though.
Re:Show HN: Command Line Challenge by notheguyouthink on Friday January 27, 2017 @09:24AM (#13499926)
If anything, i'd argue that it's incorrect. I first tried `ls -l`, then realized "oh, there could be hidden files so `-l` is not correct. Yet, `ls -la` failed too.

To list "all files", you'd need to include hidden right? Well, to be sure, at least.

Re:Show HN: Command Line Challenge by tedmiston on Friday January 27, 2017 @03:08PM (#13502221)
I took this to mean it wanted only filenames and nothing else. I used:

    ls -1
Re:Show HN: Command Line Challenge by zoidb on Thursday January 26, 2017 @01:25PM (#13493830)
Yeah it's particular about the output that it expects.
Re:Show HN: Command Line Challenge by garettmd on Thursday January 26, 2017 @01:27PM (#13493853)
I 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.
Re:Show HN: Command Line Challenge by zokier on Thursday January 26, 2017 @02:05PM (#13494243)
The 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.

Re:Show HN: Command Line Challenge by lisivka on Thursday January 26, 2017 @08:15PM (#13496937)
`ls -1b` should work correctly in your case. Option -b (or --escape) enables C-style escapes. IMHO, it should be on by default.
Re:Show HN: Command Line Challenge by zoidb on Thursday January 26, 2017 @01:42PM (#13493995)
Because 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.
Re:Show HN: Command Line Challenge by saghm on Thursday January 26, 2017 @09:04PM (#13497152)
Although 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`).
Re:Show HN: Command Line Challenge by jjnoakes on Thursday January 26, 2017 @10:07PM (#13497391)
That 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.

Re:Show HN: Command Line Challenge by JoshTriplett on Thursday January 26, 2017 @01:30PM (#13493878)
It 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.