Calling a perl script and parameters from a shell script - Unix

This is a discussion on Calling a perl script and parameters from a shell script - Unix ; I am modifying a sh script to call a perl script. The perl script returns a number.. For example ../translate.pl 12 twelve (The translation is more complicated but I need extensive use of perl's hash functionality) In my script I ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Calling a perl script and parameters from a shell script

  1. Calling a perl script and parameters from a shell script

    I am modifying a sh script to call a perl script.
    The perl script returns a number..
    For example
    ../translate.pl 12
    twelve

    (The translation is more complicated but I need extensive use of
    perl's hash functionality)

    In my script I have a simple....
    #!/bin/sh
    NUMBER=$1;
    TRANSLATED = "./translate.pl $NUMBER"
    echo $TRANSLATED

    In an ideal world TRANSLATED would return "twelve" but as of yet I
    haven't had much success in getting this to work. I just get the
    error...

    ../translate.sh: line 3: TRANSLATED: command not found

    I know this is really a simple issue but I am stumped as what the
    answer might be. I am enjoying learning shell scripting but sometimes
    I just need to use an existing perl routine.

    Any help would be appreciated.
    Thanks!
    JC

  2. Re: Calling a perl script and parameters from a shell script

    2008-03-18, 13:22(-07), worldcyclist@gmail.com:
    > I am modifying a sh script to call a perl script.
    > The perl script returns a number..
    > For example
    > ./translate.pl 12
    > twelve
    >
    > (The translation is more complicated but I need extensive use of
    > perl's hash functionality)
    >
    > In my script I have a simple....
    > #!/bin/sh


    #! /bin/sh -

    (note that on some systems like Solaris, the standard sh is not
    in /bin)

    > NUMBER=$1;


    NUMBER=${1?}

    > TRANSLATED = "./translate.pl $NUMBER"


    TRANSLATED=$(./translate.pl "$NUMBER")

    > echo $TRANSLATED


    printf '%s\n' "$TRANSLATED"

    Note that command substitution ($(...) or `...`) removes all
    trailing newline characters.

    --
    Stéphane

  3. Re: Calling a perl script and parameters from a shell script

    Stephane, thank you so much for your assistance and not laughing TOO
    hard at me for not knowing this very basic thing.
    I discovered that backticks and no spaces can be your friend.

    My solution was..
    TRANSLATED=`./translate.pl $NUMBER`

    Thank you so much again.
    JC
    --------------------------------------------------------------------------
    On Mar 18, 4:25 pm, Stephane CHAZELAS wrote:
    > 2008-03-18, 13:22(-07), worldcycl...@gmail.com:
    >
    > > I am modifying a sh script to call a perl script.
    > > The perl script returns a number..
    > > For example
    > > ./translate.pl 12
    > > twelve

    >
    > > (The translation is more complicated but I need extensive use of
    > > perl's hash functionality)

    >
    > > In my script I have a simple....
    > > #!/bin/sh

    >
    > #! /bin/sh -
    >
    > (note that on some systems like Solaris, the standard sh is not
    > in /bin)
    >
    > > NUMBER=$1;

    >
    > NUMBER=${1?}
    >
    > > TRANSLATED = "./translate.pl $NUMBER"

    >
    > TRANSLATED=$(./translate.pl "$NUMBER")
    >
    > > echo $TRANSLATED

    >
    > printf '%s\n' "$TRANSLATED"
    >
    > Note that command substitution ($(...) or `...`) removes all
    > trailing newline characters.
    >
    > --
    > Stéphane



  4. Re: Calling a perl script and parameters from a shell script

    2008-03-18, 13:34(-07), worldcyclist@gmail.com:
    > Stephane, thank you so much for your assistance and not laughing TOO
    > hard at me for not knowing this very basic thing.
    > I discovered that backticks and no spaces can be your friend.
    >
    > My solution was..
    > TRANSLATED=`./translate.pl $NUMBER`

    [...]

    `...` is the old form, still recognised by modern shells though.

    Note that leaving a variable reference ($NUMBER above) unquoted
    has a very special meaning in shells.

    It would be the equivalent of calling a "split" operator and a
    "glob" operator on each word resulting of the splitting in other
    languages. For instance, in perl that would be something like:

    map glob split($IFS_regex, $NUMBER)

    It's a good habit to have to always quote variable references.

    TRANSLATED=`./translate.pl "$NUMBER"`

    or:

    TRANSLATED=$(./translate.pl "$NUMBER")

    --
    Stéphane

+ Reply to Thread