Find the answer to your Linux question:
Results 1 to 5 of 5
Hi everyone, I have a perl script called " test " that I would like to run using a different name instead of typing " perl test " For example ...
  1. #1
    Linux User
    Join Date
    Jul 2007
    Location
    Greece
    Posts
    277

    executing a perl script

    Hi everyone,

    I have a perl script called "test" that I would like to run using a different name instead of typing
    "perl test"
    For example how could I run the script test using the word "locate".

    Can somebody please tell me how I can do this?

    Thanks a lot
    One Love!!!

  2. #2
    Just Joined! hunter_thom's Avatar
    Join Date
    Apr 2010
    Posts
    89
    Not entirely sure what you mean by using the word 'locate'. Are you referring to the locate tool or do you want the command 'locate' to run your script?

    If you start your script with:

    Code:
    #!/usr/bin/perl
    and issue a

    Code:
    chmod +x /path/to/script
    it can be executed by cd'ing to that directory and issuing a

    Code:
    ./test
    If you want it executable from anywhere you need to put it in your path. For example you could put it in /usr/local/bin as that is in the $PATH for many distros. To be sure, you can check the path with:

    Code:
    echo $PATH
    and put the script in one of the directories mentioned.

    Does that help? Not sure I understood your question entirely about locate.

  3. #3
    Linux User
    Join Date
    Jul 2007
    Location
    Greece
    Posts
    277
    Thanks for your reply.

    No, I am not referring to the linux command "locate".
    It could be any name, let's say "ajax".

    I was thinking whether is possible to when I type ajax to run the script called "test".
    Something like an alias name or soft link?
    One Love!!!

  4. #4
    Just Joined! hunter_thom's Avatar
    Join Date
    Apr 2010
    Posts
    89
    Ah cool, gotcha.

    3 quick ways I can think of off top of my head:

    1. Copy the script and rename it to xyz.
    2. Use ln to link to that other script like:
    Code:
    ln -s /path/to/script /path/to/new/link
    3. Use aliases. For example:
    Code:
    alias blah='scriptname'

  5. #5
    Linux User
    Join Date
    Jul 2007
    Location
    Greece
    Posts
    277
    Legend!!!

    Thank you.
    One Love!!!

Posting Permissions

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