Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

[Linux & perl] Command line arguments!

  1. Nov 11, 2012 #1
    I am in process of leraning Linux. I have been structed in understanding of command line arguments and @ARGV in perl.
    What is command line arguments? Really, i have no idea.
    Though, i have implemented a short program in perl to list this command line arguments but i couldn't see any list when i run my program.

    #! /usr/bin/perl

    foreach (@ARGV) {
    print "$_\n";

    Can any one help with basic information what does this command line arguments and how the perl is accessing them?

    Thank you.
  2. jcsd
  3. Nov 11, 2012 #2


    User Avatar

    Staff: Mentor

    Suppose you have the script stored in a file named args.pl. Then type this at the command prompt:

    ./args.pl one two three

    What do you see? ("one two three" are the command line arguments to the script)
  4. Nov 11, 2012 #3
    Yes, this i understood before itself. What is use of this? if it prints argumetns then what? How it would be useful in practically?
  5. Nov 11, 2012 #4


    User Avatar

    Staff: Mentor

    it's just a demonstration of how to get the command line arguments, without regard to how you're going to use them.

    By using command-line arguments, you can write scripts that behave like Unix/Linux command-line commands.
  6. Nov 11, 2012 #5


    User Avatar

    Staff: Mentor

    Type at your command prompt:


    ls *.pl

    ls -al

    It is the same command (list) but in each case output is different - thanks to the command argument.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Similar Threads for Linux perl Command Date
Linux in Windows Feb 23, 2018
Operating system concepts in an app by Linux System calls Nov 16, 2017
C/++/# How to open a window in just C++ (g++ linux) ? Mar 16, 2017
Linux Software useful for PhD Sep 3, 2016
I love perl May 17, 2015