ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have sles 10 . A user has a default shell of tcsh. I want to run a script which has to use ksh . In that script only some variables are exported, which will be used in subsequent scripts which are called inside it.
But the variables are not exported.
I am unable to find whether its a conflict of shell or what ??
I tried with debug mode, it only displays the command but not execute anyone ..
Click here to see the post LQ members have rated as the most helpful post in this thread.
Is this simply a case of the script being executed instead of sourced? If not, could you reproduce the problem with a minimal version of your script(s) and post here?
Is this simply a case of the script being executed instead of sourced? If not, could you reproduce the problem with a minimal version of your script(s) and post here?
If I understand correctly a tcsh user runs the ksh shell script (first lines illustrated in the OP) which goes on to run other scripts (calling method and language not known; depth of calls not known) which at some depth echo $VARIABLE does not work ...
If I understand correctly a tcsh user runs the ksh shell script (first lines illustrated in the OP) which goes on to run other scripts (calling method and language not known; depth of calls not known) which at some depth echo $VARIABLE does not work ...
It might help to know the missing details.
I commented the line calling other scripts, and the same result.
If the default shell is /bin/tcsh, the ksh script cannot be sourced because in that case the sha-bang will be treated as a comment and ignored and the export statements will return a command not found error. Your only option is to change the ksh script to the C-shell equivalent, using setenv in place of export and again by sourcing it instead of executing.
If the default shell is /bin/tcsh, the ksh script cannot be sourced because in that case the sha-bang will be treated as a comment and ignored and the export statements will return a command not found error. Your only option is to change the ksh script to the C-shell equivalent, using setenv in place of export and again by sourcing it instead of executing.
If the values will not inherit, how they will be passed to the scripts called inside the main one ?
These two statements are in sharp contrast to each other:
Quote:
Originally Posted by divyashree
No actually I do echo outside the script in the shell, after executing the script ..
Quote:
Originally Posted by divyashree
If the values will not inherit, how they will be passed to the scripts called inside the main one ?
It's still not clear what is the sequence of events. Your first statement means you launch a script containing the export statements and then try to echo them after the script has terminated. In that case you will not see the changes since the parent shell does not inherit the child's environment. The second statement means you have a script which calls other scripts inside it: in this case the exported variables should be visible from the childs.
Here is a working example using a /bin/ksh script from a /bin/tcsh default shell:
Code:
$ cat > script.sh
#!/bin/ksh
export LOCAL=PLMDTST
export DB_VENDOR=ORA
export MTI_ROOT=/user/omfprod
./script_child.sh
$ chmod +x script.sh
$ cat > script_child.sh
#!/bin/ksh
echo "The LOCAL variable is: $LOCAL"
echo "The DB_VENDOR variable is: $DB_VENDOR "
echo "The MTI_ROOT variable is: $MTI_ROOT"
$ chmod +x script_child.sh
$ ./script.sh
The LOCAL variable is: PLMDTST
The DB_VENDOR variable is: ORA
The MTI_ROOT variable is: /user/omfprod
Can you reproduce this behavior on your machine? Does it works exactly as in my example?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.