It would be nice to have to have some sort of hints for beginners. Hint 1: tells you command, Hint 2: tells which options/flags you might need, Hint 3: shows (a) solution
You might also encourage people to look up manpages. For instance, someone who doesn't know about "grep -h" may want to look at the manpage for grep. You could make "man grep" link to http://man7.org/linux/man-pages/man1/grep.1.html .
Tab completion doesn't always include all files; for instance, it doesn't include split-me.txt
Have you considered logging all unique successful solutions (filtering out minor whitespace differences) to each challenge? That would let people who have completed each challenge see other potential approaches to the problem, and perhaps learn about new commands.
> You should support bash's double-star wildcard, which works recursively
It depends on what the educational goals are, but alternatively OP could swing on the opposite direction and go with a very vanilla POSIX sh style shell (maybe dash) to discourage bashisms.
I might of course be bit biased because `find` is one of my favorite utils (generally with -exec instead of -print0|xargs -0) and I practically never use newfangled doublestar globbing
> I really like this; reminiscent of the Python Challenge, but for shell.
> You should support bash's double-star wildcard, which works recursively. Several of the challenges that currently require
> find -name 'access.log' -print0 | xargs -0 somecommand
> could just use
> somecommand /access.log
This challenge was where I stopped, and for this exact reason. Then again, I am a zsh user, so maybe I'm spoiled...
I stopped after 'Print the relative file paths, one path per line for all files that start with "access.log" in the current directory.' It didn't like my BSD find options.
The finale was weird for me, kinda anticlimactic (back to "hello world"); is that how it's expected to behave? No "finished" message or something? Or is my NoScript interfering somehow?
She is betraying us! Russia alone must save Europe.
Our gracious sovereign recognizes his high vocation
and will be true to it. That is the one thing I have
faith in! Our good and wonderful sovereign has to
perform the noblest role on earth, and he is so virtuous
and noble that God will not forsake him. He will fulfill
his vocation and crush the hydra of revolution, which
has become more terrible than ever in the person of this
murderer and villain!
# Correct!
# You have a new challenge!
# Print "hello world".
# Hint: There are many ways to print text on
# the command line, one way is with the 'echo'
# command.
#
# Try it below and good luck!
#
bash(0)> printf "hello world"
hello world
# Correct!
bash(0)>
# Print "hello world".
# Hint: There are many ways to print text on
# the command line, one way is with the 'echo'
# command.
#
# Try it below and good luck!
#
bash(0)> echo '"hello world".'
"hello world".
bash(0)>
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.
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.
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.
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.
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`).
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.
1) It would be nice to have something special happen when you solve all the puzzles, rather than going back to the first. Some javascript balloons dropping from the ceiling? ;_)
2) Some of the problems, it's hard to tell why an answer doesn't work. A side-by-side diff showing my results compared to the expected results might help?
3) After solving (perhaps just one, or maybe all), I'd love to see other people's solutions. That'd be quite educational.
I really enjoyed this, it was a nice way to practice/learn some command line tricks. In particular I got better acquainted with the find command. Nice work! My only suggestion would be to have an option to show a solution (yours or perhaps even a user-submitted one) if you get stuck on a particular challenge.
There is no concept of an integer on an argument vector. Quoting in bash just escapes IFS characters (usually whitespace) to control whether to include them in a given argument on the vector, but these arguments (as passed to exec) are always character strings (with or without quoting).
After completing the challenges (only had to lookup references on bash parameter expansion and how to read lines without parsing them), I would say that it might be helpful to have some reference information available whether via clicking to a third party URL. It'd also be _really_ nifty to be able to compare my solutions against others' solutions.
I'm making something related as a side project too, and the major problem I have right now is showing a terminal on the page. As you can see I'm relying on archaic methods... https://term.surge.sh
Have you considered running the commands directly in JavaScript, rather than via AWS? With some work, you could run everything inside emscripten in the browser, and then you don't need to worry about security, sandboxing, or scaling.
It looks a bit like the cwd is shared between multiple users accessing the site? I suddenly got errors that access.log disappears, after which my pwd seemed to randomly change.
Nothing is shared in fact every time you submit a command you get a new subshell in a new container. If it is reproducible I will track down the problem.
I got stuck on this one too. Strangely "find . -delete" worked fine. I'm getting Internal Server Error" now, so perhaps a victim of it's own popularity?
This is a really fun idea, and I enjoyed going thru it. I like the fact that it doesn't matter how you get the answer, as long as it's right (seq 100 | tr '\n' ' ').
This would be a really useful product as part of the interview process for technical people. I'd ask candidates to self-identify their expertise level, let them skip questions, and consult google as much as they wanted. You could have different subjects and maybe mix and match - shell, powershell, python, postgres etc.
The problem I'm having with this is that the solutions I would use to solve these aren't acceptable answers. But it is interesting to find other examples that do work. These shells are extremely restrictive.
It could be an intermittent problem as this is getting a lot of traffic right now. If it is reproducible please link the challenge or submit a github issue.
That may be true but the message from grep shows that $! wasn't expanded by the execution evironment.
BTW i get
# Print "hello world".
# Hint: There are many ways to print text on
# the command line, one way is with the 'echo'
# command.
#
# Try it below and good luck!
#
bash(0)> printf "hello world"
Internal Server Error
bash(️)>
history expansion is normally only enabled for interactive shells. They could turn it on, but if there isn't any history because this isn't really interactive, it wouldn't do anything useful.
Oh ya, I shouldn't have said answer, because uniq is not a way to the answer, just something I naturally reached for while trying to figure out an answer.
This is really cool, good work! As others have mentioned, hints/etc would definitely be helpful for beginners. I want to post this in our work chat for the less Unix oriented folks, but they'd just be lost
It does appear to handle glob expansion. Some of the levels have files within subdirectories, which isn't always completely clear from the challenge text. In the level you're trying, access.log might not be in the current directory.
Ironically, it also involved awk! But I used it to prepend line numbers, which uniq and sort can ignore, then re-sort it according to line numbers. Very much not an ideal solution!
The description for remove_duplicate_lines needs some clarification, because as written it sounds like either "uniq" or "uniq -u". You should explicitly say that you want the first instance of every duplicated line printed, and all other duplicates not printed, even if not adjacent.