Running shell script with parameter in GCP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running shell script with parameter in GCP
# 1  
Old 10-22-2019
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:
Code:
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:

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

Any help/idea/suggestion is most welcome.

That sample code:
Code:
a=10 #Will be replaced by a=$1
b=20 #Will be replaced by b=$2
sum=$(( $a + $b ))
echo $sum


Last edited by saps19; 10-22-2019 at 09:33 AM..
# 2  
Old 10-22-2019
Hi,

Here it is in a very simple format.

Code:
#!/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
# 3  
Old 10-22-2019
Try the -s option. man sh:
Quote:
-s stdin Read commands from standard input (set automatically if no file arguments are present).
Code:
gsutil cat gs://sample-bkt/transaction_test/sample_scripts/test.sh | sh -s 12 14


Last edited by RudiC; 10-22-2019 at 09:25 AM..
This User Gave Thanks to RudiC For This Post:
# 4  
Old 10-22-2019
[Deleted]. Let me try as RudiC suggested.

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

Thank you RudiC, it worked like a charm. Smilie

This thread can be closed now.


Cheers,
Saptarshi.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Passing shell script parameter value to awk command in side the script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff |... (1 Reply)
Discussion started by: Sarita Behera
1 Replies

2. Post Here to Contact Site Administrators and Moderators

Unable to pass shell script parameter value to awk command in side the same script

Variable I have in my shell script diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk -F'~' ''$2 == "$id"' {print $0}' > $new I could see value of $id is not passing to the awk... (0 Replies)
Discussion started by: Ashunayak
0 Replies

3. Shell Programming and Scripting

Script Shell Parameter

Hi I have two shell script, the second script takes as a parameter the output variable of the first script, please how to retrieve the variable from the first script to pass as a parameter to the second script? Script1.sh i=0 i=$(($i + 1)) Script2.sh echo $1 Thank you (0 Replies)
Discussion started by: chercheur111
0 Replies

4. UNIX for Dummies Questions & Answers

Parameter change in shell script

How can i chnage the parameter value in shell script. file name is icare_mmi_cls.com, iside that the parameter name is 10.100.1.2" replace the address to bep-sftp.cce.com. can you please provide me with examples. Thanks. (3 Replies)
Discussion started by: damodarreddys
3 Replies

5. Shell Programming and Scripting

parameter value change in shell script

How can i chnage the parameter value in shell script. file name is icare_mmi_cls.com, inside that the parameter name is 10.100.1.2" replace the address to bep-sftp.cce.com. can you please provide me with examples. Thanks Double post - check your PMs and follow the rules, thanks. (0 Replies)
Discussion started by: damodarreddys
0 Replies

6. AIX

Passing a parameter to a shell script?

I would like to run a compress script on files in certain directories. My compress_script.sh is just basically compress file* In order for me to use this I have to copy it into each directory and run it. How can I state the directory on the command line with the compress script so it... (2 Replies)
Discussion started by: NycUnxer
2 Replies

7. Shell Programming and Scripting

simple shell - how to get a parameter typed in a shell script

Hi, I am new to unix and using linux 7.2. I would like to create a script that would make it easyer for me to run my java programms. At the moment I have to type java myJavaprogram I am trying to write a script that will allow me to type something like this "myscript myJavaprogram" or maybe... (4 Replies)
Discussion started by: cmitulescu
4 Replies

8. Shell Programming and Scripting

Shell script with date parameter

Hi All I have a shell script which calls all the Teradata Utiltyes . There is a sudden change in the requirment . What i'm asked to do is pass on the DATE to the shell script which should take the date automatically and run the utilityes. i.e. the date should not be passed on... (5 Replies)
Discussion started by: vinayrao
5 Replies

9. Shell Programming and Scripting

replacing parameter in shell script

I have a script file as below named test1.sh sed -e 's/xxxkeys/$1/g' template1.asp > template1.txt sed -e 's/xxxkeys/$2/g' template2.asp > template2.txt sed -e 's/xxxkeys/$3/g' template3.asp > template3.txt sed -e 's/xxxkeys/$4/g' template4.asp > template4.txt I want to replace $1 with a,... (1 Reply)
Discussion started by: satgur
1 Replies

10. Shell Programming and Scripting

parameter file for a shell script

Hi I was able to pass parameters to a shell script from the command line but now, I am trying to make the shell script to get those parameters/values from a file. Please give me ideas how to do this or if you have an example or website that shows how to do this. I tried searches but it... (2 Replies)
Discussion started by: bryan
2 Replies
Login or Register to Ask a Question