Search code examples
bashshellsh

How to construct gradle command in the shell script


HI I had a shell script file ,I am trying to build the gradle command by passing arguments to the shell script file

Each time i generate the gradle command string, it's failing to execute.

If i manually hard code the values, it's Executing properly.

1

Script execution:

echo ${SPEC_DIR}   printing  variable output // specs 
echo $TAG printing  variable output// SANITY
echo $PARALLEL_RUN printing  variable output// true

sh scripts/latest_smoketestvalidation_scripts/Test_scripts/execute_smoketest_New.sh $PARALLEL_RUN $TAG $SPEC_DIR


Ex :

    parallel_run=${1}
        echo $parallel_run

        tag=${2}
        echo $tag

        spec_Dir=`echo ${3} | sed 's/,/ /g'`
        echo $spec_Dir
        echo ./gradlew gauge -PinParallel=$parallel_run -Ptags=\"$tag\" -Penv=tenantSmokeTest -PspecsDir=${spec_Dir}
       ./gradlew clean
       Working-->       ./gradlew gauge -PinParallel=true -Ptags="SANITY" -Penv=tenantSmokeTest -PspecsDir=specs

Not Working -->      # ./gradlew gauge -PinParallel=$parallel_run -Ptags=\"$tag\" -Penv=tenantSmokeTest -PspecsDir=${spec_Dir}

Solution

  • gradle gets upset by the quotes it receives in your "non-working" example. Write it as

    ... -Ptags="$tag" ...
    

    or, equivalently (but perhaps clearer),

    ... "-Ptags=$tag" ...