in reply to creating Shell Script using Perl

Add use strict; use warnings; to your code for some enlightment.

Look up "interpolation" if you need another clue.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^2: creating Shell Script using Perl
by pratikmonu (Novice) on Sep 06, 2017 at 05:25 UTC

    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.

      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
      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:  <%-{-{-{-<