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:
my $diff1 = system("sh diff.sh"); my $diff2 = system("sh diff1.sh");
diff.sh:
a=diff aaa ccc
diff1.sh:
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...

diff aaa bbb
... 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.

But then, wouldn't it be easier to avoid the *.sh wrappers and put that into the Perl script too?

my $diff1 = system("diff aaa ccc >/dev/null 2>&1"); my $diff2 = system("diff aaa bbb >/dev/null 2>&1");
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.
Please be aware that $diff1 and $diff2 contain 0 on success but not necessarily 1 on error since catched signals are encoded into the return value (details in system).

Finally, CPAN offers a lot of modules when searching for diff. Might be worth a check...

HTH

In reply to Re: How to return value of a variable from shell script to perl script by Perlbotics
in thread How to return value of a variable from shell script to perl script by babp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.