LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-02-2005, 04:08 AM   #1
subu_s
Member
 
Registered: Jun 2004
Posts: 36

Rep: Reputation: 15
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
 
Old 09-02-2005, 04:53 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,276

Rep: Reputation: 170Reputation: 170
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
 
Old 09-02-2005, 05:12 AM   #3
subu_s
Member
 
Registered: Jun 2004
Posts: 36

Original Poster
Rep: Reputation: 15
Thanks, it worked
 
Old 09-02-2005, 05:13 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,276

Rep: Reputation: 170Reputation: 170
a pleasure
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing parameters to a shell script neocookie Linux - General 5 10-20-2005 11:44 AM
help changing case on arguments to bourne shell script Maldain Programming 2 05-03-2005 10:18 AM
Apache passing arguments to a shell script disabled? mikeyt_333 Linux - Security 3 08-03-2004 06:09 PM
Passing variables from AWK script to my shell script BigLarry Programming 1 06-12-2004 04:32 AM
Issue with recursive script passing arguments gauge73 Linux - Newbie 0 01-06-2004 07:16 PM


All times are GMT -5. The time now is 01:26 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration