#1  
Old 7th August 2007, 18:04
mopsos mopsos is offline
Junior Member
 
Join Date: Feb 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default [SHELL] script in script

Hi,

I have a problem with the execution of a script in a script.
I want recover a variable in a script and test this in a other .

For exemple :
A script : sc1.sh
Code:
#!/bin/sh
var=3
A script : sc2.sh
Code:
#!/bin/sh
sh /folder/sc1.sh
if [ var -eq 3 ]
echo "goods"
fi
But this is bad.

I try with export var , but it's not good too.
Can you say me how can I do this?

Thx.
Reply With Quote
Sponsored Links
  #2  
Old 7th August 2007, 18:49
mopsos mopsos is offline
Junior Member
 
Join Date: Feb 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I try this
sc1.sh :
Code:
#!/bin/sh
var=1
sh /folder/sc2.sh $var
sc2.sh :
Code:
#!/bin/sh
echo $1
But The system didn't accept a variable in the command sh only a "word" (
ex: sh /folder/sc2.sh var .

Where is the problem?
Reply With Quote
  #3  
Old 8th August 2007, 12:32
geekman geekman is offline
Member
 
Join Date: Sep 2006
Location: Sydney, Australia
Posts: 56
Thanks: 1
Thanked 10 Times in 10 Posts
Send a message via ICQ to geekman Send a message via MSN to geekman
Default

So if I understand you correctly, you want to pass one variable onto another script? Theres two ways that come to mind straight away:

* Lets say the two scripts are in the same directory...
Example 1
----------

Script 1:

Code:
#!/bin/sh

returnvar=1
echo $returnvar
Script 2:
Code:
#!/bin/sh

# This should set $var to whatever script1 outputs.
var=`./script1`

echo Passed: $var
Example 2:
----------

Script 1:
Code:
#!/bin/sh

returnvar=3
#We are sending $returnvar as the first argument to script2
./script2 $returnvar
Script 2:
Code:
#!/bin/sh

echo Passed $1
From my experience in a debian environment this would likely work, no idea what you are using, though none of this has been tested.

Thanks, hope it helps.
Reply With Quote
  #4  
Old 8th August 2007, 14:42
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,752 Times in 2,582 Posts
 
Default

Quote:
Originally Posted by mopsos
Hi,

I have a problem with the execution of a script in a script.
I want recover a variable in a script and test this in a other .

For exemple :
A script : sc1.sh
Code:
#!/bin/sh
var=3
A script : sc2.sh
Code:
#!/bin/sh
sh /folder/sc1.sh
if [ var -eq 3 ]
echo "goods"
fi
But this is bad.
I'd do it like this:

sc1.sh:

Code:
var=3
sc2.sh:

Code:
#!/bin/sh
. /folder/sc1.sh
if [ $var -eq 3 ]
echo "goods"
fi
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Subdomain redirect to script as argument cooljai Server Operation 0 12th June 2007 17:41
apache2 problem laser144 Server Operation 8 15th March 2007 18:32
Windows PHP script problem richj1232003 Programming/Scripts 1 2nd November 2006 10:01
Could someone test this script? For server configuration danf.1979 Installation/Configuration 2 22nd July 2006 23:40
Executing ICON script lawson Programming/Scripts 3 28th December 2005 21:51


All times are GMT +2. The time now is 02:16.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.