Shell commands and scripts support

Re: Shell commands and scripts support

by Richard Lobb -
Number of replies: 0
bash isn't supported as a language out of the box. However, most languages give you a way to run shell scripts, so it's easy enough to write bash questions.

For example, using Python the following template (for which is_combinator must be unchecked) should be usable for many simple bash questions. The bash script that's run consists of the contents of the testcase 'test' field followed by the student answer.

import subprocess

script = """{{ TEST.testcode | e('py') }}""" + '\n' + """{{ STUDENT_ANSWER | e('py') }}"""
input = """{{ TEST.stdin | e('py') }}"""

with open('', 'w') as outfile:
    outfile.write(script)['/bin/bash', ''], text=True, input=input)

Here's a trivial example - the exported question is attached. Note in the exported question that I've set the Ace language - the language used to syntax-colour the student answer - to 'sh', while the sandbox language remains as Python.

Sample bash question

If you want many of these questions you should convert the question to a question prototype, so that you have your own question type, e.g. just 'bash'. However, if you're new to CodeRunner you might want to hold off until you're a bit more familiar with it. And please read the documentation, as there are pitfalls.

Note: the attached question has had minimal testing so you will almost certainly want to modify it. I've never set bash questions for my students, so it may not even be the sort of thing you had in mind. If that's the case, please give an example of the sort of question you want to set.