Find the answer to your Linux question:
Results 1 to 2 of 2
When executing the following shell script in (#!/bin/sh) I need to pass in 3 variables. Variable $2("C2P Services") is being read in by the subscript as two separate variables therefore ...
  1. #1
    Just Joined!
    Join Date
    Aug 2010
    Posts
    4

    String Variable count issue in Subscript

    When executing the following shell script in (#!/bin/sh) I need to pass in 3 variables. Variable $2("C2P Services") is being read in by the subscript as two separate variables therefore my variable count check fails thinking I've passed 4 vars instead of 3. When I execute with var 2 being only a single word it works fine but I need to pass the entire string including the space as show below.

    $ ./test-script.sh update "C2P Services" y

    Script content

    run_login_test ../bin/testServices.sh $1 "$2" $3

    Subscript being called where failure occurs in (../bin/testServices.sh)

    echo params echo here -$1- -"$2"- -$3- -$4-
    echo num of param $#
    if [ $# -eq 2 -a "$1" = "list" ]
    then
    serviceName="$2"
    exec "$dir/cbib-was-client.sh" service-availability -service "$serviceName"
    elif [ $# -eq 3 -a "$1" = "update" ]
    then
    echo here -$1- -"$2"- -$3-
    serviceName="$2"
    if [ "$3" = "y" -o "$3" = "Y" ]
    then
    available="true"
    elif [ "$3" = "n" -o "$3" = "N" ]
    then
    available="false"
    else
    usage
    fi
    exec "$dir/cbib-was-client.sh" service-update-availability -service "$serviceName" -available "$available"
    else
    usage
    fi



    What can I do to enforce the subscript to ensure $2 is read in as full string rather than two separate values?

    Thanks

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Is the "run_login_test" a script as well (I assume it is)? Then "$2" will be two parts when it gets to testServices.sh. You need to further encapsulate it, as in
    Code:
    run_login_test ../bin/testServices.sh $1 "'$2'" $3
    or
    Code:
    run_login_test ../bin/testServices.sh $1 "\"$2\"" $3
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

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