I'm trying to run a very simple shell script:
cd /tmp echo "$KMVAR_var1" > file1.txt echo "$KMVAR_var2" > file2.txt diff file1.txt file2.txt > diff_result.txt
I don't actually want the
diff results in a file, I want them in a variable returned by the shell script action. But because that was failing, I tried the above to write it to a file instead. But it still failed (with the generic failed in shell script message).
It works fine if I run those commands directly in Terminal. But here's where it gets weird; if I do the following…
cd /tmp echo "$KMVAR_var1" > file1.txt echo "$KMVAR_var2" > file2.txt diff file1.txt file2.txt > diff_result.txt echo "foo"
…then it works fine: The file is created, and contains the proper results. It doesn't matter what the next command is;
cd or whatever—just anything at all. But when
diff is the last line in the shell script, it errors out.
I am completely befuddled by this. I did work around it, as I didn't want to have to write a file to disk and then read it back, by doing this:
cd /tmp echo "$KMVAR_var1" > file1.txt echo "$KMVAR_var2" > file2.txt echo "`diff file1.txt file2.txt`"
I save that result to a variable, and it works perfectly. But why the heck is it failing on
diff if it's the last command?