- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Setting variables in a sh (Posix) shell by calling...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-03-2003 12:02 PM
тАО06-03-2003 12:02 PM
Can this be done? Everytime I call the csh scripts upon exiting the variables are lost to the calling script. I have tried declaring the .login script to use /bin/csh and calling it with a leading '.' from my sh script, but this leads Posix to attempt to translate the .login script which it can not since it is written in csh.
Can any one assist?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-03-2003 12:11 PM
тАО06-03-2003 12:11 PM
Re: Setting variables in a sh (Posix) shell by calling a csh script ???
You must do something like have the child write to a file and have the parent read the file and set the variables. If the other script were POSIX shell then you could use the "." command to include the other script. It actually becomes a part of the foreground process.
e.g.
echo "Stuff"
. ./myenv.sh
echo "More Stuff"
In this case, any variables set in myenv.sh would be in effect because this did not spawn a child process.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-03-2003 12:14 PM
тАО06-03-2003 12:14 PM
Re: Setting variables in a sh (Posix) shell by calling a csh script ???
WHY?
Cshell will read POSIX variable, and translate them to a C-Shell format. POSIX does not take external variables into consideration when it launches.
POSIX shell will read the .profile and system profile, but could care less what another shell has set before it launches. There is another issue, which is more obvious.. The variables are not set nor maintained the same (hence why C-SHell converts them).
You need to do 1 of 3 things..
Convert your script to cshell, use an external parser (I.E. Perl) to convert them, or convert your variables to posix shell.
Regards,
Shannon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-03-2003 12:22 PM
тАО06-03-2003 12:22 PM
Solutioncat .login | awk '/^set/' | grep -v path | while read a b
do
export $b
done
I grep'ed out the path vairable as this one won't work due to syntax. If you don't need the path variable, this should work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-03-2003 02:50 PM
тАО06-03-2003 02:50 PM
Re: Setting variables in a sh (Posix) shell by calling a csh script ???
#!/usr/bin/sh -x
if [ -z "${DO_CSH_SOURCE}" ]
then
export DO_CSH_SOURCE=1
exec csh -xc "source ~/.login && exec $0"
fi
# continue normally
Remember to use setenv in .login if you want the variables available to POSIX. It's kinda dirty, but it gets the job done.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2003 05:13 AM
тАО06-04-2003 05:13 AM
Re: Setting variables in a sh (Posix) shell by calling a csh script ???
Sorry, but I dont see
set HOST=`/bin/hostname`
as a script. I do see
set USERNAME=`whoami`
set OS=`uname -s`
if ( -f "/tmp/$USERNAME.lock" ) then
set SESSION="CURRENT"
else
set SESSION="FREE"
setenv PATH ( /apps/$OS/bin $path )
set LOCKFILE="/tmp/$USERNAME.lock"
touch $LOCKFILE
run_my_app
rm $LOCKFILE
endif
as a script.
So what happens if you cat a file with this content and try to just grep/awk out the set strings, and parse into POSIX?
It assigns a bunch of crap, so is broken. The dependancy on the "if" statement negates what you gave as an answer to the problems.
Now, the next step in your logic would be to convert my c-shell "if" statements to Posix. Guess what? Just like in POSIX, you can write "if" statements in multiple ways. So there are always going to be failures in this method as well.
So the answers given will work in the simple case of not a script, but setting simple variables. Add any form of intelligence to the script and it's not possible without alot of work.
Depending on how smart your .login, .cshrc, or other c-shell script file is, dictates how difficult this task really is.
Regards,
Shannon