Find the answer to your Linux question:
Results 1 to 6 of 6
Hellooooo, I am trying to write a simple Perl script that displays the version of Linux I have from etc/issue . Initially, I used grep but this printed out the ...
  1. #1
    Linux User
    Join Date
    Jul 2007
    Location
    Greece
    Posts
    277

    A script that displays the first line of file

    Hellooooo,

    I am trying to write a simple Perl script that displays the version of Linux I have from etc/issue.
    Initially, I used grep but this printed out the whole file. I found out about the head command, which I think, it is what I was looking for.
    When I type head -n1 etc/issue it works fine.
    I get: Fedora Core release 6 (Zod), but it doesn't work when I put it, in a script like it's shown below:

    print "\n Linux Version: "
    system ("head -n1 etc/issue");


    Can somebody please tell me what I am doing wrong?

    Thank you, everyone.

  2. #2
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845
    Try:

    Code:
    print "\n Linux Version: "
    system ("head -n1 /etc/issue");
    (I've added a / before etc)
    Linux User #453176

  3. #3
    Linux User
    Join Date
    Jul 2007
    Location
    Greece
    Posts
    277
    Hi Kieren,

    I did try that but :drown:...
    The error I get is: syntax error at prog1.pl line 23, near "system"

  4. #4
    Linux User
    Join Date
    Jul 2007
    Location
    Greece
    Posts
    277
    Right!!
    There is a ; missing!!! at the end of print command line.

    Sorry for the false alarm!!! However, now it doesn't open the file I want.
    The error I get is: Linux Version: head: cannot open `etc/issue' for reading: No such file or directory

  5. #5
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845
    Now try adding the / before etc

    Either that or run the script from /
    Linux User #453176

  6. #6
    Linux User
    Join Date
    Jul 2007
    Location
    Greece
    Posts
    277
    Hoooorayy!!!

    Thank you Kieren!!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...