LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-13-2010, 01:27 AM   #1
dsids
Member
 
Registered: Mar 2006
Distribution: FC4
Posts: 184

Rep: Reputation: 31
how to pass arguments in scripts


Hi,

I am calling script 2 from script 1.

Is it possible for me to pass the output from script 2 to script 1 as the value of a variable.

for eg..

path=`/XXX/XXX/script2.sh`

echo $path


Thanks
 
Old 12-13-2010, 02:34 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Why don't you try it?
 
Old 12-13-2010, 02:45 AM   #3
dsids
Member
 
Registered: Mar 2006
Distribution: FC4
Posts: 184

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by catkin View Post
Why don't you try it?
I did try it .. but it didn't work out. I am able to run the script either by sourcing it simply by mentioning the absolute path to the script. I am not able to pass the output of script2 to the variable in script1
 
Old 12-13-2010, 08:07 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
path=`/XXX/XXX/script2.sh` should assign whatever script2.sh writes to stdout to the variable path, as this command line session shows
Code:
c@CW8:/tmp$ echo '#!/bin/bash
var=$( /tmp/script2.sh )
echo var is $var' > /tmp/script1.sh
c@CW8:/tmp$ echo '#!/bin/bash
echo foo' > /tmp/script2.sh
c@CW8:/tmp$ chmod +x script*.sh
c@CW8:/tmp$ /tmp/script1.sh 
var is foo
I used $( ) in preference to ` ` because it is easier to see but they work the same when used in this simple way.

Might help if you posted your script.
 
  


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
How to pass all arguments to a function stormcloud Linux - General 4 07-08-2010 03:15 AM
[SOLVED] How to pass arguments to a function using a loop 10110111 Programming 2 03-01-2010 03:24 PM
How to pass arguments in a shell script? Drigo Linux - Newbie 1 11-14-2009 11:55 AM
Looking for a more effecient way to pass arguments to functions. RHLinuxGUY Programming 10 05-01-2006 10:52 PM
How can we pass arguments to installpkg ? frenchi Slackware 3 04-23-2004 06:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:27 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration