I have not used shell scripting in ages. I have searched online for help but have not found adequate guides..
Here is the code I am trying to understand:
#!/bin/sh
# -*-sh-*-
if gcc $1 &> cmp_out; then
if ! ./a.out &> run_out; then
exit 0; # Success.
fi
fi
exit 1; # Failure.
what is cmp_out, and run_out? Are these std_out?
I know that &> is a redirection instruction. But i do not get what that means in this scripts syntax in the slightest bit.
I am looking for a high level overview of what this script is doing. If you need more information about why i am using this script let me know. I will include more about the why.
In short it is an included example of delta debugging (//www.st.cs.uni-saarland.de/dd/)
Shell scripting is hard because it is not easy to get started. There are many different ways to write scripts, as well as many different versions of the same language and there's a huge gap between experts and beginners.
Shell scripting is not a single language but, because it uses some natural language commands, it's easy to learn, even without a programming background. However, each shell scripting dialect is considered a language, and if you plan more complex activities, shells take a lot of practice.
You can learn this language in this course called Linux Shell Scripting through many projects, which will take you around two weeks to a month to complete.
This script takes one argument, the name of a source file. It compiles that source file with gcc
and if that compilation succeeds it executes the result. (By default, gcc
writes the executable as a file named a.out
.)
If the compilation fails, you're in luck, because the script saves the output (both standard output and standard error) into a file called cmp_out
. And if the executed result produces any output, it saves that in run_out
. The script itself writes nothing to stderr or stdout. Even if gcc
isn't found, that error will end up in cmp_out
.
The strangest thing about the script is that it inverts the exit status of the execution, using the exclamation point after the if
. If executing a.out
fails, the script exits with 0, success. If a.out
succeeds, the script exits with 1, failure, which is also what it does if the compilation fails. Maybe the exclamation point is an error? The semicolon after the integers are unnecessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With