perl with shell dont accept variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • winlinfix
    New Member
    • Mar 2008
    • 3

    perl with shell dont accept variable

    Hi

    I am using running one perl command using shell scripts, but it won’t take variable
    Code:
    #!/bin/sh
    ar="/usr/local/apache/conf"
    perl -00ne '/$1/ && print $_' $ar/httpd.conf  > domstat.txt
    I am passing following things on command line
    ./domcheck.sh domainname.com
    but perl unable to understand $1 even its not highlight as variable.
    Last edited by eWish; Mar 28 '08, 12:29 AM. Reason: Please use code tags
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    Originally posted by winlinfix
    Hi

    I am using running one perl command using shell scripts, but it won’t take variable
    Code:
    #!/bin/sh
    ar="/usr/local/apache/conf"
    perl -00ne '/$1/ && print $_' $ar/httpd.conf  > domstat.txt
    I am passing following things on command line
    ./domcheck.sh domainname.com
    but perl unable to understand $1 even its not highlight as variable.
    Where does $1 get defined?

    Comment

    • winlinfix
      New Member
      • Mar 2008
      • 3

      #3
      HI,


      $1 = command line variable
      it means i am passing

      ./domcheck.sh domainname.com

      $1 = domainname.com

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        I think you may need to ask on a shell scripting forum, I do not have enough sh experience to know what the problem is. $1 is also a variable used by perl internally, but I am not sure if that would be a problem. Try this and see what happens:

        Code:
        #!/bin/sh
        perl -e ' print $1;'
        just pass your shell script a simple string and see if it gets printed by perl. If not then I think there is a conflict in trying to use the special variable $1 for this purpose.

        Comment

        • numberwhun
          Recognized Expert Moderator Specialist
          • May 2007
          • 3467

          #5
          Originally posted by KevinADC
          I think you may need to ask on a shell scripting forum, I do not have enough sh experience to know what the problem is. $1 is also a variable used by perl internally, but I am not sure if that would be a problem. Try this and see what happens:

          Code:
          #!/bin/sh
          perl -e ' print $1;'
          just pass your shell script a simple string and see if it gets printed by perl. If not then I think there is a conflict in trying to use the special variable $1 for this purpose.
          I have to agree with Kevin. Run his test above and see if it works. My first feeling is that it might cause an issue with Perl as it has a $1 as well, but if his test works, it should work then.

          Regards,

          Jeff

          Comment

          • winlinfix
            New Member
            • Mar 2008
            • 3

            #6
            Hi,


            Thankx for the help but i found another way to solve my problem.
            Code:
            #!/bin/sh
            
            echo "perl -00ne '/$1/ && print \$_' $ar/httpd.conf.bak27marn" > vl.sh
            /bin/sh vl.sh
            it is working fine.
            as perl and shell both are differnt language they do understand different syntax so it would be good to redirect result in one file and run as perl.

            Thank you
            Last edited by eWish; Apr 1 '08, 03:25 AM. Reason: Please use code tags

            Comment

            Working...