datacamp / shellwhat

https://shellwhat.readthedocs.io
GNU Affero General Public License v3.0
2 stars 8 forks source link

Implement way to check use of history commands in shell courses #40

Open filipsch opened 6 years ago

filipsch commented 6 years ago

@gvwilson commented on Thu May 17 2018

From https://github.com/datacamp/courses-intro-to-unix-shell/issues/129: if the user types !cat to repeat the last cat command, the user input we see in the SCT is cat filename (or whatever they last typed), not !cat, because history expansion is done before we get the text to check.

machow commented 6 years ago

@filipsch this is not ideal, but history expansion is not an issue for the NormalExercise. It will see !cat

(context here: https://github.com/datacamp/shellbackend#kernel-limitations)

gvwilson commented 6 years ago

Thanks @machow - why does the expansion show up in NormalExercise but not in ConsoleExercise ??

machow commented 6 years ago

@gvwilson the NormalExercise is similar to writing bash code in a file. The backend receives the raw code in that file and decides how to run it / passes it to the SCTs. In a ConsoleExercise, the student is delivering STDIN to a terminal, which could be doing anything to that input. Seeing

> !cat

when a student types !cat is just a side effect of how the shell is running at that moment in time (for example, if they had vim open and typed !cat the result would be very different). There is no "student code". All we know is that they typed a stream of characters (including delete, etc..), and some ascii canvas thing has drawn a bunch of characters.

Through bash hooks and black magic, we can get back what code they are running when they run it, and give it to the SCTs. However, bash doesn't see !cat. Very early on when bash is interpreting !cat it expands it. This happens before bash even chops commands into separate "words".

(the issue referenced in the README I linked above points to the relevant bash docs)

filipsch commented 6 years ago

I think this issue is not worth looking into. It's going to be used in 5 to 10 exercises at most in the coming year (currently only 1).