The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Passing variables to sed rogers42 Shell Programming and Scripting 3 10-29-2007 02:42 PM
Passing variables to sed jfisch Shell Programming and Scripting 3 03-07-2005 07:25 AM
Passing awk Variables gozer13 Shell Programming and Scripting 3 01-04-2005 04:32 PM
Passing Variables to Awk Bab00shka Shell Programming and Scripting 2 10-05-2004 07:18 AM
passing variables sounder123 Shell Programming and Scripting 1 06-10-2004 09:19 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-11-2008
pxy2d1 pxy2d1 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 24
Passing string variables

HI all,
Very new to shell programming and just wanted some help on how to solve the following problem.
I have a small shell script which searches a given file and extracts some string parameters. I want to now be able to call this script from another shell script and somehow pass the parameters back to the calling script where I can assign them to variables and use them.
Any help would be appreciated.
  #2 (permalink)  
Old 08-11-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,259
It could be something like this:

Code:
PARAM_LIST=`script_that_produces_parameters.sh`
And then work through the output/parameters stored in the variable with for/do/done, as an example.
  #3 (permalink)  
Old 08-11-2008
pxy2d1 pxy2d1 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 24
But how are they returned from the called script.

For example I have three string parameters in my called script:
s1,s2,s3

so how would PARAM_LIST=called.sh retrieve my three strings.

Thanks for your help
  #4 (permalink)  
Old 08-11-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,259
Your called.sh has to display this params, they should be it's output. No idea how you get them else? Are they written in a file instead?
  #5 (permalink)  
Old 08-11-2008
pxy2d1 pxy2d1 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 24
They are not currently written to a file but that might be the best way to retieve them. I could write to a tmp file and then read from the temp file before deleting it.

Thanks for your help
  #6 (permalink)  
Old 08-11-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,259
When they script retrieving the parameters is not writing them to files, they should be printed on the screen I guess.
So if you execute your script as shown with double backtiks enclosed and assigning it's output to a variable, that should work, as long as the output is not full of stuff you don't need which might force to cut out what you need.

If no other script etc. is using your retrieved parameters, maybe think about putting everything together in one script and use functions inside to give it a bit structure and flexibility.
  #7 (permalink)  
Old 08-11-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
Quote:
Originally Posted by pxy2d1 View Post
But how are they returned from the called script.

For example I have three string parameters in my called script:
s1,s2,s3

so how would PARAM_LIST=called.sh retrieve my three strings.

Thanks for your help
here's what caller.sh may look like.

Code:
PARM_LIST=$(/path/to/called.sh)
echo PARM_LIST is $PARM_LIST
here's what called.sh may look like.

Code:
S1="String1"
S2="String2"
S3="String3"
echo $S1 $S2 $S3
So when you run caller.sh it outputs

Code:
./caller.sh
PARM_LIST is String1 String2 String3
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:02 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0