|
|
|
|
|
by adrusi
3942 days ago
|
|
No such example; after all, you can spawn a shell subprocess in any of those. There's just certain types of tasks where you can more clearly express your intent in a shell script. If, for example, you need to spawn a ton of subprocesses, you can do that in any scripting language, but shell is designed from the ground up to launch subprocesses — it's most basic purpose is to launch programs. And so while I can't give an example of something that can only be done in a shell script, here's a shell script that I wrote a few weeks ago that would have been a pain in the neck to express in any other language: #!/bin/sh
cd "$(dirname "$0")"
for test in *.in; do
test="$(basename "$test" .in)"
infile="$test.in"
outfile="$test.out"
output="$(./whofrom "$infile" 2>&1)"
expected="$(cat "$outfile")"
if [ "$output" != "$expected" ]; then
echo "Failed test $test"
echo "Expected: $expected"
echo "Actual: $output"
echo
fi
if ! valgrind --error-exitcode=1 --leak-check=full ./whofrom "$infile" 2>/dev/null >/dev/null; then
echo "Failed test $test"
valgrind -q --leak-check=full ./whofrom "$infile"
echo
fi
done
|
|
Apart from the header, the whole script is pretty much the same when comparing line-by-line.