Linux

General discussion

Shell Scripts and Exporting

Hello, I am new to Linux and we plan to develop application servers in Linux. Currently, I am trying to get Weblogic's Javabean container and Console running from a script. I can run the Console and the container from the command line no problem however, I am having difficulty getting the shell scripts to work. Help?

I mean, I can not even get the weblogic .bash_profile for the user I set up to export the PS1 variable I assigned or any other. Also, Weblogic has a setEnv.sh script to set up and export some more special variables such as JAVA_HOME but after you run the script "sh setEnv.sh" and then type "echo $Java_Home" nothing. I have already made sure weblogic owns the file,directory and permissions are set 755. This can't be rocket science and the funny thing is if I assign variables and export them in etc/profile, they sometimes work with no problem but I do not want to clutter etc/profile if I do not have to or, is there where this stuff should go anyway. Please tellme what is going wrong with my shell scripts? P.S. I am running Red Hat 6.2

All Comments

Shell Scripts and Exporting

I played around with a quick test file and found that typing "source shell.sh" set the variables I placed inside them in my local enviroment. I'll keep checking this out. I haven't messed with shell scripts in a while. Hope this helps.

Shell Scripts and Exporting

I'm not sure about this, but in order to get variables to work you can either user source a .sh file as stated above or use the users .bashrc and .profile..bashrc in users home dir is used if that users logs in and has defualt shell bash.If you instead have #!/bin/sh at the top of your start and stop scripts then this shell won't read .bashrc .profile or any other startupfiles.

Shell Scripts and Exporting

Your problem is that when you run a program or script from another script, Unix actually creates a new process which is a complete duplicate of the original process (including its environment) and runs the new script in that. Any changes to the environment are made to the duplicate environment which goes away when the new script exits. If you want to have variables change as a result of running a script, you need to "source" the script i.e. run it without creating a new process. This is done in a korne shell as follows: ". your_script" (note the leading "."). I think the same thing will work in bash.

Shell Scripts and Exporting

jpereia@sendmail.com is correct. I made the following testfile called test1: #!/bin/bash export MYVAR="this is a test"

If it is run from the command line as follows: test1 the variable is not set, but if run as follows: . test1You can type "echo $MYVAR" and see the variable and also see it with the "env" command.

The problem with your PS1 variable is that in Redhat, the user's $HOME/.bashrc script runs the /etc/bashrc file which resets the PS1 variable to a preset value. I recommend commenting out the call from $HOME/.bashrc to /etc/bashrc, and setting the PS1 var in the user's .bash_profile script. See the Linux tip at http://ctdp.homestead.com/files/os/linux/tips/index.html Tip#2 The same info may be more accessable at http://ctdp.tripod.com/os..

Start or search

Create a new discussion

If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.

Post type

Subject title

Topic Tags

Select up to 3 tags (1 tag required)

Cloud

Piracy

Security

Apple

Microsoft

IT Employment

Google

Open Source

Mobility

Social Enterprise

Community

Smartphones

Operating Systems

Windows

Mac

Malware

Tablets

Networking

Browser

Hardware

Software

Web Developerment

Linux

Off Topic

Message Body

Track this discussion and email me when there are updates

Please note: Do not post advertisements, offensive material, profanity, or personal attacks. Please remember to be considerate of other members. If you're new to the TechRepublic Forums, please read our TechRepublic Forums FAQ. All submitted content is subject to our Terms Of Use.