Running shell script with parameter in GCP

Hello Experts,

Good day all.

Issue details:
I have one sample script resides at Google Cloud storage (gs://URL) ( test.sh ) and it is having simple calculation script with two parameter hardcoded with value ( a=10, b=20 ) and getting sum output. The command I'm executing from Unix server as:

gsutil cat gs://sample-bkt/transaction_test/sample_scripts/test.sh | sh

and it is working fine.

Now if I'm trying to pass $1 and $2, then the above command is not working:

gsutil cat gs://sample-bkt/transaction_test/sample_scripts/test.sh 12 14 | sh

Any help/idea/suggestion is most welcome.

That sample code:

a=10 #Will be replaced by a=$1
b=20 #Will be replaced by b=$2
sum=$(( $a + $b ))
echo $sum

Hi,

Here it is in a very simple format.

#!/usr/bin/bash
######################################
#
# Add the arguments.
#
######################################

sum=$(( $1 + $2 ))
echo $sum

This just simply adds the two arguments, note you should test that there are two arguments.

Regards

Gull04

Try the -s option. man sh :

gsutil cat gs://sample-bkt/transaction_test/sample_scripts/test.sh | sh -s 12 14
1 Like

[Deleted]. Let me try as RudiC suggested.

--- Post updated at 07:32 AM ---

Thank you RudiC, it worked like a charm. :slight_smile:

This thread can be closed now.

Cheers,
Saptarshi.

Moderator comments were removed during original forum migration.