Show HN: Command Line Challenge
cmdchallenge.com
cmdchallenge.com
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*
instead.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.
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
This challenge was where I stopped, and for this exact reason. Then again, I am a zsh user, so maybe I'm spoiled...
Which options, specifically?
shopt -s globstar
and **/access.log*
works just it would in bash :) 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)>
What is this, Android? Sheesh.https://en.wikipedia.org/wiki/Sepp_Herberger#References_in_p...
(I would also like it if the site somehow indicated that you got to the end or congratulated you on finishing everything.)
To list "all files", you'd need to include hidden right? Well, to be sure, at least.
ls -1And this is not just some hypothetical scenario, just today at work I encountered a file with cursor movement terminal escape sequences in the filename.
ls will change the way it writes its output if it detects that stdout is a tty versus a pipe or redirect.
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.
grep -rl 500 .
wasn't accepted. Am I wrong or is it wrong?Unfortunately, since shopt globstar is disabled I ended up needing to do this:
grep 500 $(find . -type f -iname "access.log*")I used echo -e 'access.log\naccess.log.1\nREADME'. :D
grep -rl '500'
works just fine.grep -rl "500" .
doesn't work because it returns with the "./".
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.
bash(0)> pwd
Internal Server Error bash(0)> grep GET !$
+ grep GET '!$'
grep: !$: No such file or directory
Mmm. Fake bash.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(️)>Prints the same list of files as grep -l 500 * , but in a different order; doesn't pass the challenge.
Also, grep -Il 500 * doesn't include README, for some reason. file README doesn't work :-(
with LC_COLLATE=en_US.UTF-8,
sort faces.txt | uniq -c
5 (◕‿◕)
uniq treats (︺︹︺) as equal to (◕‿◕).
Copied the file to my machine to test.
I also ended up with this: https://gist.github.com/daveloyall/63485c5a08882432b138c0917...
awk '{if (!c[$0]) { print }; c[$0] = 1 }' awk '!a[$0]++' faces.txt
is a touch shorter ^^ bash(0)> awk '{print $1}' access.log*
+ awk '{print $1}' 'access.log*'
awk: cannot open access.log* (No such file or directory) awk '{printf "%2d %s\n", NR, $0}' < faces.txt | sort -k 2 -u | sort -n | sed 's/^...//'
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!awk '!h[$0] {h[$0]=1; print}' faces.txt
That is clever! Awk golf hole-in-one ;-)
Also, I learned today that cat takes a -n option to prepend line numbers to the output! My solution ended up being
cat -n faces.txt | sort -k2 -k1n | uniq -f1 | sort -nk1,1 | cut -f2-< war_and_peace.txt tr -s '!' | sed 's/!\([a-z]\)/\1/g' | sed 's/!\( [a-z]\)/\1/g' | sed 's/!\.!/./g' | sed 's/ !/ /g'
However, I don't think I learnt much from that. :-)
awk '{l++;gsub("!","");t[1]=4;t[4]=2;t[9]=3;o=$1;for(i=2;i<=NF;i++){o=o " " $i (i==t[l]?"!":"")};print o}' war_and_peace.txt seq -s ' ' 1 100Lots of the challenges have awkward/ambiguous wording like this.
(If you'd like more detailed feedback, email me -- this username @gmail)
python: command not found
:(Should this not work for challenge 9?
"grep 500 -rh --include='access.log*'"
Personally, I think that would be a bit more of a challenge than bash.