in reply to How to return value of a variable from shell script to perl script
Welcome to the Monastery, babp. You might get better feedback if you format your question a little bit more readable. Please see Markup in the Monastery (esp. <code>). (Un-)fortunately, the HTML source of this page is more readable, so let me repeat the basic parts of your question:
Perl program:diff.sh:my $diff1 = system("sh diff.sh"); my $diff2 = system("sh diff1.sh");
diff1.sh:a=diff aaa ccc
b=diff aaa bbb
The problem is, that diff.sh and diff1.sh don't do what you (probably) had in mind: The variable (a or b) is set to the string diff, then the shell tries to execute(!) aaa with argument bbb or ccc.
Suggestion (non-Perl): Correct diff.sh (analogue diff1.sh), e.g.
diff aaa bbb a=$? # do something else with $a exit $a
Which can be reduced to...
... in case you only want to execute diff. The shell (usually) returns the exec state of the last statement executed. BTW: Perl has borrowed this idea here and there (e.g. return) - although this is not best practice.diff aaa bbb
But then, wouldn't it be easier to avoid the *.sh wrappers and put that into the Perl script too?
Note the redirections to get rid of diff's output. If your version of diff supports a switch to suppress output and just return the exec state, then give the system LIST variant a try for better security.my $diff1 = system("diff aaa ccc >/dev/null 2>&1"); my $diff2 = system("diff aaa bbb >/dev/null 2>&1");
Finally, CPAN offers a lot of modules when searching for diff. Might be worth a check...
HTH
|
|---|