in reply to Re: creating Shell Script using Perl
in thread creating Shell Script using Perl

using strict and warning gives me this error:-

Variable "$FILE" is not imported at NativeUIAutomationScript.pl line 136.

Variable "$FILE" is not imported at NativeUIAutomationScript.pl line 136.

I am not really sure How to use interpolation in this function.

Replies are listed 'Best First'.
Re^3: creating Shell Script using Perl
by Happy-the-monk (Canon) on Sep 06, 2017 at 05:47 UTC

    I am not really sure How to use interpolation in this function.

    You should not. You have already thought of backslashes to mask the quote marks.

    Also put backslashes before the $ sigil of variables that should only be in use in the final shell script.

    Cheers, Sören

    Créateur des bugs mobiles - let loose once, run everywhere.
    (hooked on the Perl Programming language)

      perfect!! Worked for me.. Thanks, PR
Re^3: creating Shell Script using Perl
by AnomalousMonk (Archbishop) on Sep 06, 2017 at 05:48 UTC
    print FILE "    [[ -f \"$FILE\" ]] && grep -q \"$STRING\" \"$FILE\" && echo \"DB Installation is completed\" && break\n";

    $FILE and $STRING appear in a Perl double-quoted string. Perl will try to interpolate these Perl variables into the string, but you really intend them for the shell. In order to protect them from Perl interpolation, escape them with a  \ (backslash) (as afoken has written). So the statement would look something like (untested)
        print FILE "    [[ -f \"\$FILE\" ]] && grep -q \"\$STRING\" \"\$FILE\" && echo \"DB Installation is completed\" && break\n";
    or maybe, since you don't really seem to need Perl interpolation at all in this statement,
        print FILE '    [[ -f "$FILE" ]] && grep -q "$STRING" "$FILE" && echo "DB Installation is completed" && break', "\n";
    (or use a here-doc as kcott suggested).


    Give a man a fish:  <%-{-{-{-<