calling a program (w/ params) from within shell

Hi all,

I need to call some script (s1) from within my shell script (s2). s1 accepts parameters and I want to feed it with values of params from my script. I tried many things but none work (I am so much of a beginner), please help

one of my attempts :
.
.
.
param1="hehe"
param2="haha"

s1
echo -e "\r"
echo $param1
echo $param2

------------------------------------------------------------------------------------
PS: when I run s1 from command prompt (not from shell I do the following and it works)
>s1 ; I press return key
>enter value of param1: hehe ; I enter hehe then return key
>enter value of param2: haha ; I enter haha then return key

-------------------------------------------------------------------

hi,

please make your requirement a bit clear so that we may able to help you in writting the script.

Oh I'm sorry

I am trying to write a script (s1.sh) which calls another script that I didn't write (s2).

Usually I run s2 from the command line as:

> s2 param1=val1 param2=val2 param3=val3

how do I call s2 from my shell script s1.sh and specifiy the values of the parameters?
I hope I am more clear now, thanks for the help in advance

hi,

you can simply call the script s2 in the script s1.sh by simply mentioning

./s2.sh inside the script s1.sh

if your script s2.sh works fine on the command prompt then you will get the desired output.

thanks,
Subhendu

Subhendu

Actually I tried that before and it didn't work either
I don't know the extention of s2. All I know that it's an executable now :frowning:

Help

Have You tried

./s2.sh $param1 $param2

then they will be available as $1 and $2 in s2.sh

/Lakris

Ok. I just found out that s2 is prolly written in fortran because there are files on my machine as s2.f and s2.o
is it possible to call it from my script at all?

Please help me decide if I'm doing the write thing by writing a "shell script" to automate running this program that I can run from my command line with no problem. I've tried all your suggestions but none worked out. Should I use something else other than shell scripting?

Thanks

If You can run the program from the command line, You can most certainly run it from within a script. But Your description is still a bit unclear. I get the impression that You want to be able to be prompted for the parameters before You "send" them to s2, is that correct?

/Lakris

Ok let me try to rephrase my question

The program s2 can be run in command line by typing:

>s2 param1=val1 param2=val2
>enter value of param3: val3
>enter value of param4[2000] ;return key accepts default
> ...................

Now from within my shell script I did:

param1= val1
param2=val2
param3=val3

s2 param1=$param1 param2=$param2
echo $param3
echo -e '\r'

the program runs but with errors as it doesnt get the values of the params I feed it through my shell script correctly

The echo in your code will only run when s2 finishes. To provide $param3 as input, try this instead.

s2 param1=val param2=val2 <<HERE
val3

HERE

Whether it works or not depends on whether s2 accepts the remaining parameters as standard input; some programs explicitly read from the terminal, or use some sort of interactive front end which doesn't work with standard input.

Thanks so much!! Now that I realized when the echo is executed, it works !!!
Thanks again :slight_smile:

If you know how to pass parameters to a FOTRAN file. then hust call the obj file from you script. and pass the args to the object file.