Quote:
Originally Posted by daYz
To be more specific, in c you can "pass" a variable to another file by using the extern specifier. I wonder how a variable in a c file can be seen from within another file that is a bash script.
|
Well,
extern is a specifier telling the linker that a symbol exists in an object file different from the one you compiled with your original source file. Since, a script is not compiled into object code, there is no way to do what you describe (tell a script to look for symbols elsewhere).
There are, however, a few remedies when you have a C program calling a bash script (e.g., using the
exec family of functions).
- You might pass the variable(s) to bash as command-line parameters. You can then access the positional parameters as $1, $2, $3, etc.
- You can pass the variable(s) to bash as environment variables. That way, you can access the variables in the script using whatever identifiers you chose in the C program.