LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Passing arguments to a shell script (http://www.linuxquestions.org/questions/programming-9/passing-arguments-to-a-shell-script-359425/)

subu_s 09-02-2005 04:08 AM

Passing arguments to a shell script
 
Hi,
This problem is particular to the shell 'sh' in Solaris.

My requirement is to execute a shell script in the current shell.

I execute as ' . ./temp.sh 1 2 3 '
and temp.sh is as simple as :-
echo $1 $2 $3

However $1 $2 and $3 do not get recognised.

I can invoke the script as 'sh temp.sh 1 2 3'
or '. ./temp.sh 1 2 3' in bash. These qork ok.

My requirement is to ultimately set some env vars in the script so I need the script to run in the current shell.

Help please,
Subu

bigearsbilly 09-02-2005 04:53 AM

If you are 'dotting' the file then as you are not invoking it, as such, just including
it in the current script, so the $1 $2 $3 will be the same as the current shell.

So any vars visible in the 'calling' script will be visible in the dotted script anyway.


If you want to reset $1 $2 $3 you can use set, eg:


Code:

billym.primadtpdev>date
Friday September  2 10:48:00 BST 2005

billym.primadtpdev>set -- `date`
billym.primadtpdev>echo $3 $2 $1
2 September Friday


subu_s 09-02-2005 05:12 AM

Thanks, it worked

bigearsbilly 09-02-2005 05:13 AM

a pleasure ;)


All times are GMT -5. The time now is 11:51 PM.