Results 1 to 10 of 10
I have two scripts:
input.sh
Code:
#component
components_list()
{
_component1="server"
_component2="client"
}
#files
server()
{
_description="servercomponent"
_file1="bin/vinfo.exe"
_file2="Welcome.html"
}
client()
{
_description="clientcomponent"
_file1="Welcome.html"
}
My requirement is to find out ...
- 10-13-2008 #1Just Joined!
- Join Date
- Apr 2007
- Posts
- 59
accessing variable defined in a function in another script
I have two scripts:
input.sh
My requirement is to find out the number of _file variables defined in a particular function like in the above example for server function its 2 and for client function its 1.Code:#component components_list() { _component1="server" _component2="client" } #files server() { _description="servercomponent" _file1="bin/vinfo.exe" _file2="Welcome.html" } client() { _description="clientcomponent" _file1="Welcome.html" }
- 10-14-2008 #2Just Joined!
- Join Date
- Apr 2007
- Posts
- 59
Is it not possible to do this?
- 10-14-2008 #3Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
Well, of course it's possible. The question is, how do you intend to share the information between these two processes? You could use a file, or a pipe, for example.
- 10-14-2008 #4Just Joined!
- Join Date
- Apr 2007
- Posts
- 59
I plan to call that function from another script and then accessing the just the number of _file variables into a variable and then start reading the values one by one.
Any mechanism will do.
- 10-14-2008 #5Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
- 10-14-2008 #6Just Joined!
- Join Date
- Apr 2007
- Posts
- 59
Yes, one script will source the other script.
This is the another script which will source the input.sh
build.sh
Code:. input.sh #get the No of _file variables defined in functions 'server' and 'client' and access their values one-by-one
- 10-14-2008 #7Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
Well then, what's your problem? You are effectively running a single script, regardless of whether the functions were defined in this file or that file. Put the information in a global variable and access it from anywhere in your script.
- 10-14-2008 #8Just Joined!
- Join Date
- Apr 2007
- Posts
- 59
the problem is the variable names are same in all the functions. if you see _file1 is defined in both the functions.
Can you please tell me how to achieve my objective?
- 10-14-2008 #9Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
No. This is broken as designed.
- 10-14-2008 #10Just Joined!
- Join Date
- Apr 2007
- Posts
- 59
Yeah, may be my design is wrong. One can't have the same variables in the more than one functions.
Anyways, can I atleast access the variables names and their values?
build.sh
Code:. input.sh #get variable names and values defined in server functions


Reply With Quote
