duplicate argument 0

Discussion in 'Perl Misc' started by Ross, Oct 7, 2005.

  1. Ross

    Ross Guest

    hi everybody,
    when i try to obtain the file name by setting:

    $filename = $ARGV[0];

    i found $ARGV[0] actually contains a duplicate filename, e.g.


    /var/www/A11NRXXX.DIF//var/www/A11NRXXX.DIF

    this problem only occurs (i.e. it works normally by directly typing abc.pl
    in shell) when i use a shell script as:

    #!/bin/sh

    for F in `/bin/ls $1`;do
    /usr/bin/perl /var/www/abc.pl $1/$F
    done

    exit 0;


    any idea please?
     
    Ross, Oct 7, 2005
    #1
    1. Advertising

  2. Ross

    Paul Lalli Guest

    Ross wrote:
    > hi everybody,
    > when i try to obtain the file name by setting:
    >
    > $filename = $ARGV[0];
    >
    > i found $ARGV[0] actually contains a duplicate filename, e.g.
    >
    >
    > /var/www/A11NRXXX.DIF//var/www/A11NRXXX.DIF


    Then that's what you passed to the perl script.

    > this problem only occurs (i.e. it works normally by directly typing abc.pl
    > in shell) when i use a shell script as:
    >
    > #!/bin/sh
    >
    > for F in `/bin/ls $1`;do
    > /usr/bin/perl /var/www/abc.pl $1/$F
    > done
    >
    > exit 0;


    Your question has nothing to do with Perl. Your question would be the
    same regardless of the language in which the 'abc' script was written.
    Your question is about how to correctly pass parameters from a shell
    script.

    Your script is taking it's first argument, and performing an `ls` on
    it. It then apparently makes an assumption that this argument was a
    directory name. If, however, your script is called with a filename,
    such as '/var/www/A11NRXXX.DIF', then `ls` will return just that one
    filename as well. Therefore, you're contactenating the filename, a
    slash, and that filename again.

    You need to rethink your shell script's algorithm.

    Paul Lalli
     
    Paul Lalli, Oct 7, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bhushit Joshipura

    defaulting argument to previous argument

    Bhushit Joshipura, Dec 29, 2003, in forum: C++
    Replies:
    5
    Views:
    430
  2. Ben Kial
    Replies:
    1
    Views:
    727
    Eric Enright
    Nov 15, 2004
  3. S?ren Gammelmark
    Replies:
    1
    Views:
    1,989
    Eric Sosman
    Jan 7, 2005
  4. nw
    Replies:
    0
    Views:
    342
  5. Reckoner
    Replies:
    11
    Views:
    742
    Steven D'Aprano
    Jan 19, 2009
Loading...

Share This Page